<?php

	class Reports_proxy extends Model
	{
		public function __construct()
		{
			parent::__construct();

			$this->load->model('proxies/mahasamadhi/Mahasamadhi_registration_proxy');
            $this->load->model('proxies/mahasamadhi/Mahasamadhi_proxy');
            $this->load->model('proxies/Walk_proxy');
			$this->load->model('values/mahasamadhi/Mahasamadhi_registration_value');
		}

		public function download_file( $filePath, $fileName )
		{
			$fullPath = $filePath."/".$fileName; 

			if( file_exists($fullPath) )
			{ 			
				// Parse Info / Get Extension 
				$fsize = filesize($fullPath); 
				$ext = "csv";
				
				// Determine Content Type 
				switch ($ext) { 
				  case "csv": $ctype="application/vnd.ms-excel"; break; 
				  case "pdf": $ctype="application/pdf"; break; 
				  case "exe": $ctype="application/octet-stream"; break; 
				  case "zip": $ctype="application/zip"; break; 
				  case "doc": $ctype="application/msword"; break; 
				  case "xls": $ctype="application/vnd.ms-excel"; break; 
				  case "ppt": $ctype="application/vnd.ms-powerpoint"; break; 
				  case "gif": $ctype="image/gif"; break; 
				  case "png": $ctype="image/png"; break; 
				  case "jpeg": 
				  case "jpg": $ctype="image/jpg"; break; 
				  default: $ctype="application/force-download"; 
				} 
				
				header("Pragma: public"); // required 
				header("Expires: 0"); 
				header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 
				header("Cache-Control: private",false); // required for certain browsers 
				header("Content-Type: $ctype"); 
				header("Content-Disposition: attachment; filename=\"".$fileName."\";" ); 
				header("Content-Transfer-Encoding: binary"); 
				header("Content-Length: ".$fsize); 
				//ob_clean(); 
				flush(); 
				readfile( $fullPath );
				
				sleep(1);
				 		
				unlink( $fullPath );
			}
			else 
				die('File Not Found'); 
		}

		//Get members
		public function getMembers( $searchcriteria )
		{
			$meminfoarr = array();
						
			$searchstr = " ";
			if (!empty($searchcriteria['memberlastname']))
				$searchstr = " AND p.last_name LIKE '".$searchcriteria['memberlastname']."%' ";
			
			if (!empty($searchcriteria['memberfirstname']))
				$searchstr = $searchstr."AND p.first_name LIKE '".$searchcriteria['memberfirstname']."%' ";

			if (!empty($searchcriteria['membercity']))
				$searchstr = $searchstr."AND p.city LIKE '".$searchcriteria['membercity']."%' ";

			if ((!empty($searchcriteria['memberstate'])) and ($searchcriteria['memberstate'] != "All"))
				$searchstr = $searchstr."AND p.state = '".$searchcriteria['memberstate']."' ";

			if ((!empty($searchcriteria['centername'])) and ($searchcriteria['centername'] != "All"))
				$searchstr = $searchstr."AND cc.center_name = '".$searchcriteria['centername']."' ";

			$tmp = $this->db->query('			
					SELECT
						p.first_name,
						IFNULL(p.last_name,' . $this->db->escape("") . ') AS last_name,
						IFNULL(p.city,' . $this->db->escape("") . ') AS city,
						IFNULL(p.state,' . $this->db->escape("") . ') AS state,
						IFNULL(p.zip,' . $this->db->escape("") . ') AS zip,
						cc.center_name
						FROM person p
						INNER JOIN household_xref hxr ON hxr.person_id_fk=p.person_id
						INNER JOIN household hh ON hh.household_id=hxr.household_id_fk
						INNER JOIN cmb_reg_history crh ON crh.household_id_fk=hh.household_id
						INNER JOIN cmb_center cc ON cc.cmb_center_id=crh.cmb_center_id_fk
					WHERE
						p.enabled = 1
						AND hxr.enabled = 1
						AND hh.enabled = 1
						AND p.cmb_member = 1 ' . $searchstr .
					'GROUP BY p.person_id
					ORDER BY p.last_name ASC;
					');

			if($tmp->num_rows() > 0)
			{											  
				foreach ($tmp->result() as $memRow)
				{
					$memrec = array();
					
					$memrec['firstname'] = $memRow->first_name;
					$memrec['lastname'] = $memRow->last_name;
					$memrec['city'] = $memRow->city;
					$memrec['state'] = $memRow->state;
					$memrec['zip'] = $memRow->zip;
					$memrec['center_name'] = $memRow->center_name;					

					array_push($meminfoarr, $memrec);
				}
			}
	
			return 	$meminfoarr;		
		}

		//Get management dashboard data for specified year
		public function getManagementDashboardData( $curyear )
		{
			$prevyear = $curyear - 1;
			$dashinfoarr = array();
						
			//Get Balavihar class summary data for "Andover' center 'AM' session
			$centername = 'Andover';
			$session = 'AM';
			$gradesprev = array('n/a','Pre-K','K','1','2','3','4','5','6','7','8','9','10','11');
			$gradescur = array('Pre-K','K','1','2','3','4','5','6','7','8','9','10','11','12');
			
			for($ig = 0; $ig < count($gradescur); $ig++)
			{
				$recinfo = array();
				$prevgrade = $gradesprev[$ig];
				$curgrade = $gradescur[$ig];
				array_push($recinfo,$centername);
				array_push($recinfo,$session);
				array_push($recinfo,$prevgrade);
				array_push($recinfo,$curgrade);
				
				//Get #children for previous year class
				//-----------------------------
				$tmp = $this->db->query('			
						SELECT
						    COUNT(p.person_id) AS ' . $this->db->escape("previous") . '
						FROM bv_reg_history brh
							INNER JOIN person p ON p.person_id = brh.person_id_fk
							INNER JOIN grade g ON g.grade_name = brh.grade
							INNER JOIN cmb_center cc ON cc.cmb_center_id=brh.cmb_center_id_fk
						WHERE
							p.cmb_member = 1
							AND p.enabled = 1
							AND brh.enabled = 1
							AND brh.year = ' . $this->db->escape($prevyear) . '
							AND cc.center_name = ' . $this->db->escape($centername) . '
							AND brh.session = ' . $this->db->escape($session) . '
							AND brh.grade = ' . $this->db->escape($prevgrade) . '
						');
	
				if($tmp->num_rows() > 0)
				{											  
					array_push($recinfo,$tmp->row()->previous);
				}
				//-----------------------------

				//Get #children for current year class
				//-----------------------------
				$tmp = $this->db->query('			
						SELECT
						    COUNT(p.person_id) AS ' . $this->db->escape("current") . '
						FROM bv_reg_history brh
							INNER JOIN person p ON p.person_id = brh.person_id_fk
							INNER JOIN grade g ON g.grade_name = brh.grade
							INNER JOIN cmb_center cc ON cc.cmb_center_id=brh.cmb_center_id_fk
						WHERE
							p.cmb_member = 1
							AND p.enabled = 1
							AND brh.enabled = 1
							AND brh.year = ' . $this->db->escape($curyear) . '
							AND cc.center_name = ' . $this->db->escape($centername) . '
							AND brh.session = ' . $this->db->escape($session) . '
							AND brh.grade = ' . $this->db->escape($curgrade) . '
						');
	
				if($tmp->num_rows() > 0)
				{											  
					array_push($recinfo,$tmp->row()->current);
				}
				//-----------------------------

				//Get #children in common between previous and current year
				//-----------------------------
				$tmp = $this->db->query('			
						SELECT
						    COUNT(p.person_id) AS ' . $this->db->escape("common") . '
						FROM bv_reg_history brh
							INNER JOIN person p ON p.person_id = brh.person_id_fk
							INNER JOIN grade g ON g.grade_name = brh.grade
							INNER JOIN cmb_center cc ON cc.cmb_center_id=brh.cmb_center_id_fk
						WHERE
							p.cmb_member = 1
							AND p.enabled = 1
							AND brh.enabled = 1
							AND brh.year = ' . $this->db->escape($prevyear) . '
							AND cc.center_name = ' . $this->db->escape($centername) . '
							AND brh.session = ' . $this->db->escape($session) . '
							AND brh.grade = ' . $this->db->escape($prevgrade) . '
							AND p.person_id IN
							(
								SELECT p.person_id
								FROM bv_reg_history brh
									INNER JOIN person p ON p.person_id = brh.person_id_fk
									INNER JOIN grade g ON g.grade_name = brh.grade
									INNER JOIN cmb_center cc ON cc.cmb_center_id=brh.cmb_center_id_fk
								WHERE
									p.cmb_member = 1
									AND p.enabled = 1
									AND brh.enabled = 1
									AND brh.year = ' . $this->db->escape($curyear) . '
									AND cc.center_name = ' . $this->db->escape($centername) . '
									AND brh.session = ' . $this->db->escape($session) . '
									AND brh.grade = ' . $this->db->escape($curgrade) . ')
						');
	
				if($tmp->num_rows() > 0)
				{											  
					array_push($recinfo,$tmp->row()->common);
				}
				//-----------------------------

				//Get #children dropout between previous and current year
				//-----------------------------
				$tmp = $this->db->query('			
						SELECT
						    COUNT(p.person_id) AS ' . $this->db->escape("dropout") . '
						FROM bv_reg_history brh
							INNER JOIN person p ON p.person_id = brh.person_id_fk
							INNER JOIN grade g ON g.grade_name = brh.grade
							INNER JOIN cmb_center cc ON cc.cmb_center_id=brh.cmb_center_id_fk
						WHERE
							p.cmb_member = 1
							AND p.enabled = 1
							AND brh.enabled = 1
							AND brh.year = ' . $this->db->escape($prevyear) . '
							AND cc.center_name = ' . $this->db->escape($centername) . '
							AND brh.session = ' . $this->db->escape($session) . '
							AND brh.grade = ' . $this->db->escape($prevgrade) . '
							AND p.person_id NOT IN
							(
								SELECT p.person_id
								FROM bv_reg_history brh
									INNER JOIN person p ON p.person_id = brh.person_id_fk
									INNER JOIN grade g ON g.grade_name = brh.grade
									INNER JOIN cmb_center cc ON cc.cmb_center_id=brh.cmb_center_id_fk
								WHERE
									p.cmb_member = 1
									AND p.enabled = 1
									AND brh.enabled = 1
									AND brh.year = ' . $this->db->escape($curyear) . '
									AND cc.center_name = ' . $this->db->escape($centername) . '
									AND brh.session = ' . $this->db->escape($session) . '
									AND brh.grade = ' . $this->db->escape($curgrade) . ')
						');
	
				if($tmp->num_rows() > 0)
				{											  
					array_push($recinfo,$tmp->row()->dropout);
				}
				//-----------------------------

				//Get #children new between previous and current year
				//-----------------------------
				$tmp = $this->db->query('			
						SELECT
						    COUNT(p.person_id) AS ' . $this->db->escape("new") . '
						FROM bv_reg_history brh
							INNER JOIN person p ON p.person_id = brh.person_id_fk
							INNER JOIN grade g ON g.grade_name = brh.grade
							INNER JOIN cmb_center cc ON cc.cmb_center_id=brh.cmb_center_id_fk
						WHERE
							p.cmb_member = 1
							AND p.enabled = 1
							AND brh.enabled = 1
							AND brh.year = ' . $this->db->escape($curyear) . '
							AND cc.center_name = ' . $this->db->escape($centername) . '
							AND brh.session = ' . $this->db->escape($session) . '
							AND brh.grade = ' . $this->db->escape($curgrade) . '
							AND p.person_id NOT IN
							(
								SELECT p.person_id
								FROM bv_reg_history brh
									INNER JOIN person p ON p.person_id = brh.person_id_fk
									INNER JOIN grade g ON g.grade_name = brh.grade
									INNER JOIN cmb_center cc ON cc.cmb_center_id=brh.cmb_center_id_fk
								WHERE
									p.cmb_member = 1
									AND p.enabled = 1
									AND brh.enabled = 1
									AND brh.year = ' . $this->db->escape($prevyear) . '
									AND cc.center_name = ' . $this->db->escape($centername) . '
									AND brh.session = ' . $this->db->escape($session) . '
									AND brh.grade = ' . $this->db->escape($prevgrade) . ')
						');
	
				if($tmp->num_rows() > 0)
				{											  
					array_push($recinfo,$tmp->row()->new);				
				}
				//-----------------------------

				//Get #children attending current year class
				//-----------------------------
				$tmp = $this->db->query('			
						SELECT
						SUM(IF((bvax.status = 1),1,0)) AS ' . $this->db->escape("attend") . ',
						SUM(IF((bvax.status = 1),1,1)) AS ' . $this->db->escape("total") . '
						FROM bv_attend_xref bvax
						INNER JOIN bv_reg_history brh ON brh.person_id_fk=bvax.person_id_fk
						INNER JOIN person p ON p.person_id=brh.person_id_fk
						INNER JOIN bv_week bvw ON bvw.bv_week_id=bvax.bv_week_id_fk
						INNER JOIN cmb_center cc ON cc.cmb_center_id=brh.cmb_center_id_fk
						WHERE
						brh.enabled = 1
						AND brh.year = ' . $this->db->escape($curyear) . '
						AND bvw.year = ' . $this->db->escape($curyear) . '
						AND cc.center_name = ' . $this->db->escape($centername) . '
						AND brh.session = ' . $this->db->escape($session) . '
						AND brh.grade = ' . $this->db->escape($curgrade) . '
						AND bvw.bow_date < NOW();
					');
	
				if($tmp->num_rows() > 0)
				{											  
					array_push($recinfo,$tmp->row()->attend);
					array_push($recinfo,$tmp->row()->total);
				}
				//-----------------------------

				array_push($dashinfoarr, $recinfo);
			}
			
			//Get Balavihar class summary data for "Andover' center 'PM' session
			$centername = 'Andover';
			$session = 'PM';
			$gradesprev = array('n/a','Pre-K','K','1','2','3','4','5','6','7','8');
			$gradescur = array('Pre-K','K','1','2','3','4','5','6','7','8','9');
			
			for($ig = 0; $ig < count($gradescur); $ig++)
			{
				$recinfo = array();
				$prevgrade = $gradesprev[$ig];
				$curgrade = $gradescur[$ig];
				array_push($recinfo,$centername);
				array_push($recinfo,$session);
				array_push($recinfo,$prevgrade);
				array_push($recinfo,$curgrade);
				
				//Get #children for previous year class
				//-----------------------------
				$tmp = $this->db->query('			
						SELECT
						    COUNT(p.person_id) AS ' . $this->db->escape("previous") . '
						FROM bv_reg_history brh
							INNER JOIN person p ON p.person_id = brh.person_id_fk
							INNER JOIN grade g ON g.grade_name = brh.grade
							INNER JOIN cmb_center cc ON cc.cmb_center_id=brh.cmb_center_id_fk
						WHERE
							p.cmb_member = 1
							AND p.enabled = 1
							AND brh.enabled = 1
							AND brh.year = ' . $this->db->escape($prevyear) . '
							AND cc.center_name = ' . $this->db->escape($centername) . '
							AND brh.session = ' . $this->db->escape($session) . '
							AND brh.grade = ' . $this->db->escape($prevgrade) . '
						');
	
				if($tmp->num_rows() > 0)
				{											  
					array_push($recinfo,$tmp->row()->previous);
				}
				//-----------------------------

				//Get #children for current year class
				//-----------------------------
				$tmp = $this->db->query('			
						SELECT
						    COUNT(p.person_id) AS ' . $this->db->escape("current") . '
						FROM bv_reg_history brh
							INNER JOIN person p ON p.person_id = brh.person_id_fk
							INNER JOIN grade g ON g.grade_name = brh.grade
							INNER JOIN cmb_center cc ON cc.cmb_center_id=brh.cmb_center_id_fk
						WHERE
							p.cmb_member = 1
							AND p.enabled = 1
							AND brh.enabled = 1
							AND brh.year = ' . $this->db->escape($curyear) . '
							AND cc.center_name = ' . $this->db->escape($centername) . '
							AND brh.session = ' . $this->db->escape($session) . '
							AND brh.grade = ' . $this->db->escape($curgrade) . '
						');
	
				if($tmp->num_rows() > 0)
				{											  
					array_push($recinfo,$tmp->row()->current);
				}
				//-----------------------------

				//Get #children in common between previous and current year
				//-----------------------------
				$tmp = $this->db->query('			
						SELECT
						    COUNT(p.person_id) AS ' . $this->db->escape("common") . '
						FROM bv_reg_history brh
							INNER JOIN person p ON p.person_id = brh.person_id_fk
							INNER JOIN grade g ON g.grade_name = brh.grade
							INNER JOIN cmb_center cc ON cc.cmb_center_id=brh.cmb_center_id_fk
						WHERE
							p.cmb_member = 1
							AND p.enabled = 1
							AND brh.enabled = 1
							AND brh.year = ' . $this->db->escape($prevyear) . '
							AND cc.center_name = ' . $this->db->escape($centername) . '
							AND brh.session = ' . $this->db->escape($session) . '
							AND brh.grade = ' . $this->db->escape($prevgrade) . '
							AND p.person_id IN
							(
								SELECT p.person_id
								FROM bv_reg_history brh
									INNER JOIN person p ON p.person_id = brh.person_id_fk
									INNER JOIN grade g ON g.grade_name = brh.grade
									INNER JOIN cmb_center cc ON cc.cmb_center_id=brh.cmb_center_id_fk
								WHERE
									p.cmb_member = 1
									AND p.enabled = 1
									AND brh.enabled = 1
									AND brh.year = ' . $this->db->escape($curyear) . '
									AND cc.center_name = ' . $this->db->escape($centername) . '
									AND brh.session = ' . $this->db->escape($session) . '
									AND brh.grade = ' . $this->db->escape($curgrade) . ')
						');
	
				if($tmp->num_rows() > 0)
				{											  
					array_push($recinfo,$tmp->row()->common);
				}
				//-----------------------------

				//Get #children dropout between previous and current year
				//-----------------------------
				$tmp = $this->db->query('			
						SELECT
						    COUNT(p.person_id) AS ' . $this->db->escape("dropout") . '
						FROM bv_reg_history brh
							INNER JOIN person p ON p.person_id = brh.person_id_fk
							INNER JOIN grade g ON g.grade_name = brh.grade
							INNER JOIN cmb_center cc ON cc.cmb_center_id=brh.cmb_center_id_fk
						WHERE
							p.cmb_member = 1
							AND p.enabled = 1
							AND brh.enabled = 1
							AND brh.year = ' . $this->db->escape($prevyear) . '
							AND cc.center_name = ' . $this->db->escape($centername) . '
							AND brh.session = ' . $this->db->escape($session) . '
							AND brh.grade = ' . $this->db->escape($prevgrade) . '
							AND p.person_id NOT IN
							(
								SELECT p.person_id
								FROM bv_reg_history brh
									INNER JOIN person p ON p.person_id = brh.person_id_fk
									INNER JOIN grade g ON g.grade_name = brh.grade
									INNER JOIN cmb_center cc ON cc.cmb_center_id=brh.cmb_center_id_fk
								WHERE
									p.cmb_member = 1
									AND p.enabled = 1
									AND brh.enabled = 1
									AND brh.year = ' . $this->db->escape($curyear) . '
									AND cc.center_name = ' . $this->db->escape($centername) . '
									AND brh.session = ' . $this->db->escape($session) . '
									AND brh.grade = ' . $this->db->escape($curgrade) . ')
						');
	
				if($tmp->num_rows() > 0)
				{											  
					array_push($recinfo,$tmp->row()->dropout);
				}
				//-----------------------------

				//Get #children new between previous and current year
				//-----------------------------
				$tmp = $this->db->query('			
						SELECT
						    COUNT(p.person_id) AS ' . $this->db->escape("new") . '
						FROM bv_reg_history brh
							INNER JOIN person p ON p.person_id = brh.person_id_fk
							INNER JOIN grade g ON g.grade_name = brh.grade
							INNER JOIN cmb_center cc ON cc.cmb_center_id=brh.cmb_center_id_fk
						WHERE
							p.cmb_member = 1
							AND p.enabled = 1
							AND brh.enabled = 1
							AND brh.year = ' . $this->db->escape($curyear) . '
							AND cc.center_name = ' . $this->db->escape($centername) . '
							AND brh.session = ' . $this->db->escape($session) . '
							AND brh.grade = ' . $this->db->escape($curgrade) . '
							AND p.person_id NOT IN
							(
								SELECT p.person_id
								FROM bv_reg_history brh
									INNER JOIN person p ON p.person_id = brh.person_id_fk
									INNER JOIN grade g ON g.grade_name = brh.grade
									INNER JOIN cmb_center cc ON cc.cmb_center_id=brh.cmb_center_id_fk
								WHERE
									p.cmb_member = 1
									AND p.enabled = 1
									AND brh.enabled = 1
									AND brh.year = ' . $this->db->escape($prevyear) . '
									AND cc.center_name = ' . $this->db->escape($centername) . '
									AND brh.session = ' . $this->db->escape($session) . '
									AND brh.grade = ' . $this->db->escape($prevgrade) . ')
						');
	
				if($tmp->num_rows() > 0)
				{											  
					array_push($recinfo,$tmp->row()->new);				
				}
				//-----------------------------

				//Get #children attending current year class
				//-----------------------------
				$tmp = $this->db->query('			
						SELECT
						SUM(IF((bvax.status = 1),1,0)) AS ' . $this->db->escape("attend") . ',
						SUM(IF((bvax.status = 1),1,1)) AS ' . $this->db->escape("total") . '
                        FROM bv_attend_xref bvax
                        INNER JOIN bv_reg_history brh ON brh.person_id_fk=bvax.person_id_fk
                        INNER JOIN person p ON p.person_id=brh.person_id_fk
                        INNER JOIN bv_week bvw ON bvw.bv_week_id=bvax.bv_week_id_fk
						INNER JOIN cmb_center cc ON cc.cmb_center_id=brh.cmb_center_id_fk
						WHERE
						brh.enabled = 1
						AND brh.year = ' . $this->db->escape($curyear) . '
						AND bvw.year = ' . $this->db->escape($curyear) . '
						AND cc.center_name = ' . $this->db->escape($centername) . '
						AND brh.session = ' . $this->db->escape($session) . '
						AND brh.grade = ' . $this->db->escape($curgrade) . '
						AND bvw.bow_date < NOW();						');
	
				if($tmp->num_rows() > 0)
				{											  
					array_push($recinfo,$tmp->row()->attend);
					array_push($recinfo,$tmp->row()->total);
				}
				//-----------------------------

				array_push($dashinfoarr, $recinfo);
			}

            //Get Balavihar class summary data for "Andover' center 'PM2' session
            $centername = 'Andover';
            $session = 'PM2';
            $gradesprev = array('n/a','Pre-K','K','1','2','3','4','5','6','7');
            $gradescur = array('Pre-K','K','1','2','3','4','5','6','7','8');
            
            for($ig = 0; $ig < count($gradescur); $ig++)
            {
                $recinfo = array();
                $prevgrade = $gradesprev[$ig];
                $curgrade = $gradescur[$ig];
                array_push($recinfo,$centername);
                array_push($recinfo,$session);
                array_push($recinfo,$prevgrade);
                array_push($recinfo,$curgrade);
                
                //Get #children for previous year class
                //-----------------------------
                $tmp = $this->db->query('           
                        SELECT
                            COUNT(p.person_id) AS ' . $this->db->escape("previous") . '
                        FROM bv_reg_history brh
                            INNER JOIN person p ON p.person_id = brh.person_id_fk
                            INNER JOIN grade g ON g.grade_name = brh.grade
                            INNER JOIN cmb_center cc ON cc.cmb_center_id=brh.cmb_center_id_fk
                        WHERE
                            p.cmb_member = 1
                            AND p.enabled = 1
                            AND brh.enabled = 1
                            AND brh.year = ' . $this->db->escape($prevyear) . '
                            AND cc.center_name = ' . $this->db->escape($centername) . '
                            AND brh.session = ' . $this->db->escape($session) . '
                            AND brh.grade = ' . $this->db->escape($prevgrade) . '
                        ');
    
                if($tmp->num_rows() > 0)
                {                                             
                    array_push($recinfo,$tmp->row()->previous);
                }
                //-----------------------------

                //Get #children for current year class
                //-----------------------------
                $tmp = $this->db->query('           
                        SELECT
                            COUNT(p.person_id) AS ' . $this->db->escape("current") . '
                        FROM bv_reg_history brh
                            INNER JOIN person p ON p.person_id = brh.person_id_fk
                            INNER JOIN grade g ON g.grade_name = brh.grade
                            INNER JOIN cmb_center cc ON cc.cmb_center_id=brh.cmb_center_id_fk
                        WHERE
                            p.cmb_member = 1
                            AND p.enabled = 1
                            AND brh.enabled = 1
                            AND brh.year = ' . $this->db->escape($curyear) . '
                            AND cc.center_name = ' . $this->db->escape($centername) . '
                            AND brh.session = ' . $this->db->escape($session) . '
                            AND brh.grade = ' . $this->db->escape($curgrade) . '
                        ');
    
                if($tmp->num_rows() > 0)
                {                                             
                    array_push($recinfo,$tmp->row()->current);
                }
                //-----------------------------

                //Get #children in common between previous and current year
                //-----------------------------
                $tmp = $this->db->query('           
                        SELECT
                            COUNT(p.person_id) AS ' . $this->db->escape("common") . '
                        FROM bv_reg_history brh
                            INNER JOIN person p ON p.person_id = brh.person_id_fk
                            INNER JOIN grade g ON g.grade_name = brh.grade
                            INNER JOIN cmb_center cc ON cc.cmb_center_id=brh.cmb_center_id_fk
                        WHERE
                            p.cmb_member = 1
                            AND p.enabled = 1
                            AND brh.enabled = 1
                            AND brh.year = ' . $this->db->escape($prevyear) . '
                            AND cc.center_name = ' . $this->db->escape($centername) . '
                            AND brh.session = ' . $this->db->escape($session) . '
                            AND brh.grade = ' . $this->db->escape($prevgrade) . '
                            AND p.person_id IN
                            (
                                SELECT p.person_id
                                FROM bv_reg_history brh
                                    INNER JOIN person p ON p.person_id = brh.person_id_fk
                                    INNER JOIN grade g ON g.grade_name = brh.grade
                                    INNER JOIN cmb_center cc ON cc.cmb_center_id=brh.cmb_center_id_fk
                                WHERE
                                    p.cmb_member = 1
                                    AND p.enabled = 1
                                    AND brh.enabled = 1
                                    AND brh.year = ' . $this->db->escape($curyear) . '
                                    AND cc.center_name = ' . $this->db->escape($centername) . '
                                    AND brh.session = ' . $this->db->escape($session) . '
                                    AND brh.grade = ' . $this->db->escape($curgrade) . ')
                        ');
    
                if($tmp->num_rows() > 0)
                {                                             
                    array_push($recinfo,$tmp->row()->common);
                }
                //-----------------------------

                //Get #children dropout between previous and current year
                //-----------------------------
                $tmp = $this->db->query('           
                        SELECT
                            COUNT(p.person_id) AS ' . $this->db->escape("dropout") . '
                        FROM bv_reg_history brh
                            INNER JOIN person p ON p.person_id = brh.person_id_fk
                            INNER JOIN grade g ON g.grade_name = brh.grade
                            INNER JOIN cmb_center cc ON cc.cmb_center_id=brh.cmb_center_id_fk
                        WHERE
                            p.cmb_member = 1
                            AND p.enabled = 1
                            AND brh.enabled = 1
                            AND brh.year = ' . $this->db->escape($prevyear) . '
                            AND cc.center_name = ' . $this->db->escape($centername) . '
                            AND brh.session = ' . $this->db->escape($session) . '
                            AND brh.grade = ' . $this->db->escape($prevgrade) . '
                            AND p.person_id NOT IN
                            (
                                SELECT p.person_id
                                FROM bv_reg_history brh
                                    INNER JOIN person p ON p.person_id = brh.person_id_fk
                                    INNER JOIN grade g ON g.grade_name = brh.grade
                                    INNER JOIN cmb_center cc ON cc.cmb_center_id=brh.cmb_center_id_fk
                                WHERE
                                    p.cmb_member = 1
                                    AND p.enabled = 1
                                    AND brh.enabled = 1
                                    AND brh.year = ' . $this->db->escape($curyear) . '
                                    AND cc.center_name = ' . $this->db->escape($centername) . '
                                    AND brh.session = ' . $this->db->escape($session) . '
                                    AND brh.grade = ' . $this->db->escape($curgrade) . ')
                        ');
    
                if($tmp->num_rows() > 0)
                {                                             
                    array_push($recinfo,$tmp->row()->dropout);
                }
                //-----------------------------

                //Get #children new between previous and current year
                //-----------------------------
                $tmp = $this->db->query('           
                        SELECT
                            COUNT(p.person_id) AS ' . $this->db->escape("new") . '
                        FROM bv_reg_history brh
                            INNER JOIN person p ON p.person_id = brh.person_id_fk
                            INNER JOIN grade g ON g.grade_name = brh.grade
                            INNER JOIN cmb_center cc ON cc.cmb_center_id=brh.cmb_center_id_fk
                        WHERE
                            p.cmb_member = 1
                            AND p.enabled = 1
                            AND brh.enabled = 1
                            AND brh.year = ' . $this->db->escape($curyear) . '
                            AND cc.center_name = ' . $this->db->escape($centername) . '
                            AND brh.session = ' . $this->db->escape($session) . '
                            AND brh.grade = ' . $this->db->escape($curgrade) . '
                            AND p.person_id NOT IN
                            (
                                SELECT p.person_id
                                FROM bv_reg_history brh
                                    INNER JOIN person p ON p.person_id = brh.person_id_fk
                                    INNER JOIN grade g ON g.grade_name = brh.grade
                                    INNER JOIN cmb_center cc ON cc.cmb_center_id=brh.cmb_center_id_fk
                                WHERE
                                    p.cmb_member = 1
                                    AND p.enabled = 1
                                    AND brh.enabled = 1
                                    AND brh.year = ' . $this->db->escape($prevyear) . '
                                    AND cc.center_name = ' . $this->db->escape($centername) . '
                                    AND brh.session = ' . $this->db->escape($session) . '
                                    AND brh.grade = ' . $this->db->escape($prevgrade) . ')
                        ');
    
                if($tmp->num_rows() > 0)
                {                                             
                    array_push($recinfo,$tmp->row()->new);              
                }
                //-----------------------------

                //Get #children attending current year class
                //-----------------------------
                $tmp = $this->db->query('           
                        SELECT
                        SUM(IF((bvax.status = 1),1,0)) AS ' . $this->db->escape("attend") . ',
                        SUM(IF((bvax.status = 1),1,1)) AS ' . $this->db->escape("total") . '
                        FROM bv_attend_xref bvax
                        INNER JOIN bv_reg_history brh ON brh.person_id_fk=bvax.person_id_fk
                        INNER JOIN person p ON p.person_id=brh.person_id_fk
                        INNER JOIN bv_week bvw ON bvw.bv_week_id=bvax.bv_week_id_fk
                        INNER JOIN cmb_center cc ON cc.cmb_center_id=brh.cmb_center_id_fk
                        WHERE
                        brh.enabled = 1
                        AND brh.year = ' . $this->db->escape($curyear) . '
                        AND bvw.year = ' . $this->db->escape($curyear) . '
                        AND cc.center_name = ' . $this->db->escape($centername) . '
                        AND brh.session = ' . $this->db->escape($session) . '
                        AND brh.grade = ' . $this->db->escape($curgrade) . '
                        AND bvw.bow_date < NOW();                       ');
    
                if($tmp->num_rows() > 0)
                {                                             
                    array_push($recinfo,$tmp->row()->attend);
                    array_push($recinfo,$tmp->row()->total);
                }
                //-----------------------------

                array_push($dashinfoarr, $recinfo);
            }

			//Get Balavihar class summary data for "MetroWest' center 'PM' session
			$centername = 'MetroWest';
			$session = 'PM';
			$gradesprev = array('n/a','Pre-K','K','1','2','3','4','5','6','7','8','9','10','11');
			$gradescur = array('Pre-K','K','1','2','3','4','5','6','7','8','9','10','11','12');
			
			for($ig = 0; $ig < count($gradescur); $ig++)
			{
				$recinfo = array();
				$prevgrade = $gradesprev[$ig];
				$curgrade = $gradescur[$ig];
				array_push($recinfo,$centername);
				array_push($recinfo,$session);
				array_push($recinfo,$prevgrade);
				array_push($recinfo,$curgrade);
				
				//Get #children for previous year class
				//-----------------------------
				$tmp = $this->db->query('			
						SELECT
						    COUNT(p.person_id) AS ' . $this->db->escape("previous") . '
						FROM bv_reg_history brh
							INNER JOIN person p ON p.person_id = brh.person_id_fk
							INNER JOIN grade g ON g.grade_name = brh.grade
							INNER JOIN cmb_center cc ON cc.cmb_center_id=brh.cmb_center_id_fk
						WHERE
							p.cmb_member = 1
							AND p.enabled = 1
							AND brh.enabled = 1
							AND brh.year = ' . $this->db->escape($prevyear) . '
							AND cc.center_name = ' . $this->db->escape($centername) . '
							AND brh.session = ' . $this->db->escape($session) . '
							AND brh.grade = ' . $this->db->escape($prevgrade) . '
						');
	
				if($tmp->num_rows() > 0)
				{											  
					array_push($recinfo,$tmp->row()->previous);
				}
				//-----------------------------

				//Get #children for current year class
				//-----------------------------
				$tmp = $this->db->query('			
						SELECT
						    COUNT(p.person_id) AS ' . $this->db->escape("current") . '
						FROM bv_reg_history brh
							INNER JOIN person p ON p.person_id = brh.person_id_fk
							INNER JOIN grade g ON g.grade_name = brh.grade
							INNER JOIN cmb_center cc ON cc.cmb_center_id=brh.cmb_center_id_fk
						WHERE
							p.cmb_member = 1
							AND p.enabled = 1
							AND brh.enabled = 1
							AND brh.year = ' . $this->db->escape($curyear) . '
							AND cc.center_name = ' . $this->db->escape($centername) . '
							AND brh.session = ' . $this->db->escape($session) . '
							AND brh.grade = ' . $this->db->escape($curgrade) . '
						');
	
				if($tmp->num_rows() > 0)
				{											  
					array_push($recinfo,$tmp->row()->current);
				}
				//-----------------------------

				//Get #children in common between previous and current year
				//-----------------------------
				$tmp = $this->db->query('			
						SELECT
						    COUNT(p.person_id) AS ' . $this->db->escape("common") . '
						FROM bv_reg_history brh
							INNER JOIN person p ON p.person_id = brh.person_id_fk
							INNER JOIN grade g ON g.grade_name = brh.grade
							INNER JOIN cmb_center cc ON cc.cmb_center_id=brh.cmb_center_id_fk
						WHERE
							p.cmb_member = 1
							AND p.enabled = 1
							AND brh.enabled = 1
							AND brh.year = ' . $this->db->escape($prevyear) . '
							AND cc.center_name = ' . $this->db->escape($centername) . '
							AND brh.session = ' . $this->db->escape($session) . '
							AND brh.grade = ' . $this->db->escape($prevgrade) . '
							AND p.person_id IN
							(
								SELECT p.person_id
								FROM bv_reg_history brh
									INNER JOIN person p ON p.person_id = brh.person_id_fk
									INNER JOIN grade g ON g.grade_name = brh.grade
									INNER JOIN cmb_center cc ON cc.cmb_center_id=brh.cmb_center_id_fk
								WHERE
									p.cmb_member = 1
									AND p.enabled = 1
									AND brh.enabled = 1
									AND brh.year = ' . $this->db->escape($curyear) . '
									AND cc.center_name = ' . $this->db->escape($centername) . '
									AND brh.session = ' . $this->db->escape($session) . '
									AND brh.grade = ' . $this->db->escape($curgrade) . ')
						');
	
				if($tmp->num_rows() > 0)
				{											  
					array_push($recinfo,$tmp->row()->common);
				}
				//-----------------------------

				//Get #children dropout between previous and current year
				//-----------------------------
				$tmp = $this->db->query('			
						SELECT
						    COUNT(p.person_id) AS ' . $this->db->escape("dropout") . '
						FROM bv_reg_history brh
							INNER JOIN person p ON p.person_id = brh.person_id_fk
							INNER JOIN grade g ON g.grade_name = brh.grade
							INNER JOIN cmb_center cc ON cc.cmb_center_id=brh.cmb_center_id_fk
						WHERE
							p.cmb_member = 1
							AND p.enabled = 1
							AND brh.enabled = 1
							AND brh.year = ' . $this->db->escape($prevyear) . '
							AND cc.center_name = ' . $this->db->escape($centername) . '
							AND brh.session = ' . $this->db->escape($session) . '
							AND brh.grade = ' . $this->db->escape($prevgrade) . '
							AND p.person_id NOT IN
							(
								SELECT p.person_id
								FROM bv_reg_history brh
									INNER JOIN person p ON p.person_id = brh.person_id_fk
									INNER JOIN grade g ON g.grade_name = brh.grade
									INNER JOIN cmb_center cc ON cc.cmb_center_id=brh.cmb_center_id_fk
								WHERE
									p.cmb_member = 1
									AND p.enabled = 1
									AND brh.enabled = 1
									AND brh.year = ' . $this->db->escape($curyear) . '
									AND cc.center_name = ' . $this->db->escape($centername) . '
									AND brh.session = ' . $this->db->escape($session) . '
									AND brh.grade = ' . $this->db->escape($curgrade) . ')
						');
	
				if($tmp->num_rows() > 0)
				{											  
					array_push($recinfo,$tmp->row()->dropout);
				}
				//-----------------------------

				//Get #children new between previous and current year
				//-----------------------------
				$tmp = $this->db->query('			
						SELECT
						    COUNT(p.person_id) AS ' . $this->db->escape("new") . '
						FROM bv_reg_history brh
							INNER JOIN person p ON p.person_id = brh.person_id_fk
							INNER JOIN grade g ON g.grade_name = brh.grade
							INNER JOIN cmb_center cc ON cc.cmb_center_id=brh.cmb_center_id_fk
						WHERE
							p.cmb_member = 1
							AND p.enabled = 1
							AND brh.enabled = 1
							AND brh.year = ' . $this->db->escape($curyear) . '
							AND cc.center_name = ' . $this->db->escape($centername) . '
							AND brh.session = ' . $this->db->escape($session) . '
							AND brh.grade = ' . $this->db->escape($curgrade) . '
							AND p.person_id NOT IN
							(
								SELECT p.person_id
								FROM bv_reg_history brh
									INNER JOIN person p ON p.person_id = brh.person_id_fk
									INNER JOIN grade g ON g.grade_name = brh.grade
									INNER JOIN cmb_center cc ON cc.cmb_center_id=brh.cmb_center_id_fk
								WHERE
									p.cmb_member = 1
									AND p.enabled = 1
									AND brh.enabled = 1
									AND brh.year = ' . $this->db->escape($prevyear) . '
									AND cc.center_name = ' . $this->db->escape($centername) . '
									AND brh.session = ' . $this->db->escape($session) . '
									AND brh.grade = ' . $this->db->escape($prevgrade) . ')
						');
	
				if($tmp->num_rows() > 0)
				{											  
					array_push($recinfo,$tmp->row()->new);				
				}
				//-----------------------------

				//Get #children attending current year class
				//-----------------------------
				$tmp = $this->db->query('			
						SELECT
						SUM(IF((bvax.status = 1),1,0)) AS ' . $this->db->escape("attend") . ',
						SUM(IF((bvax.status = 1),1,1)) AS ' . $this->db->escape("total") . '
                        FROM bv_attend_xref bvax
                        INNER JOIN bv_reg_history brh ON brh.person_id_fk=bvax.person_id_fk
                        INNER JOIN person p ON p.person_id=brh.person_id_fk
                        INNER JOIN bv_week bvw ON bvw.bv_week_id=bvax.bv_week_id_fk
						INNER JOIN cmb_center cc ON cc.cmb_center_id=brh.cmb_center_id_fk
						WHERE
						brh.enabled = 1
						AND brh.year = ' . $this->db->escape($curyear) . '
						AND bvw.year = ' . $this->db->escape($curyear) . '
						AND cc.center_name = ' . $this->db->escape($centername) . '
						AND brh.session = ' . $this->db->escape($session) . '
						AND brh.grade = ' . $this->db->escape($curgrade) . '
						AND bvw.bow_date < NOW();
					');
	
				if($tmp->num_rows() > 0)
				{											  
					array_push($recinfo,$tmp->row()->attend);
					array_push($recinfo,$tmp->row()->total);
				}
				//-----------------------------

				array_push($dashinfoarr, $recinfo);
			}

			return $dashinfoarr;
		}
		
		//Get dashboard info for mahasamadhi registrations for specified year
		public function getMahasamadhiDashboardData( $specifiedyear )
		{
			$reginfoarr = array();			

			//Total registered for current year
			$tmp = $this->db->query('			
					SELECT
						COUNT(mrh.ms_reg_history_id) AS totnumreg
					FROM ms_reg_history mrh
					WHERE
						mrh.enabled = 1
						AND mrh.year = ' . $this->db->escape($specifiedyear) . '
					');

			if($tmp->num_rows() > 0)
			{											  
				$reginfoarr['totnumreg'] = $tmp->row()->totnumreg;
				$totreg = $tmp->row()->totnumreg;
			}
			else
			{
				$reginfoarr['totnumreg'] = '0';
				$totreg = 0;
			}

			//Total paid registrants for current year
			$tmp = $this->db->query('			
					SELECT
						COUNT(mrh.ms_reg_history_id) AS regpaid
					FROM ms_reg_history mrh
					WHERE
						mrh.enabled = 1
						AND mrh.year = ' . $this->db->escape($specifiedyear) . '
						AND mrh.payment_status = 1
					');

			if($tmp->num_rows() > 0)
			{											  
				$reginfoarr['regpaid'] = $tmp->row()->regpaid;
				$totpaid = $tmp->row()->regpaid;
			}
			else
			{
				$reginfoarr['regpaid'] = '0';
				$totpaid = 0;
			}

			//Total paid by paypal registrants for current year
			$tmp = $this->db->query('			
					SELECT
						COUNT(mrh.ms_reg_history_id) AS regpaidpp
					FROM ms_reg_history mrh
					WHERE
						mrh.enabled = 1
						AND mrh.year = ' . $this->db->escape($specifiedyear) . '
						AND mrh.payment_status = 1
						AND mrh.payment_type = ' . $this->db->escape("paypal") . '
					');

			if($tmp->num_rows() > 0)
			{											  
				$reginfoarr['regpaidpp'] = $tmp->row()->regpaidpp;
			}
			else
			{
				$reginfoarr['regpaidpp'] = '0';
			}

			//Total paid by check registrants for current year
			$tmp = $this->db->query('			
					SELECT
						COUNT(mrh.ms_reg_history_id) AS regpaidcheck
					FROM ms_reg_history mrh
					WHERE
						mrh.enabled = 1
						AND mrh.year = ' . $this->db->escape($specifiedyear) . '
						AND mrh.payment_status = 1
						AND mrh.payment_type = ' . $this->db->escape("check") . '
					');

			if($tmp->num_rows() > 0)
			{											  
				$reginfoarr['regpaidcheck'] = $tmp->row()->regpaidcheck;
			}
			else
			{
				$reginfoarr['regpaidcheck'] = '0';
			}

			//Total unpaid registrants for current year
			$tmp = $this->db->query('			
					SELECT
						COUNT(mrh.ms_reg_history_id) AS regunpaid
					FROM ms_reg_history mrh
					WHERE
						mrh.enabled = 1
						AND mrh.year = ' . $this->db->escape($specifiedyear) . '
						AND mrh.payment_status <> 1
					');

			if($tmp->num_rows() > 0)
			{											  
				$reginfoarr['regunpaid'] = $tmp->row()->regunpaid;
			}
			else
			{
				$reginfoarr['regunpaid'] = '0';
			}

			//Total funds committed for current year
			$tmp = $this->db->query('			
					SELECT
						SUM(mrh.amount_committed) AS fundscom
					FROM ms_reg_history mrh
					WHERE
						mrh.enabled = 1
						AND mrh.year = ' . $this->db->escape($specifiedyear) . '
					');

			if($tmp->num_rows() > 0)
			{											  
				$reginfoarr['fundscom'] = $tmp->row()->fundscom;
				$totcom = $tmp->row()->fundscom;
			}
			else
			{
				$reginfoarr['fundscom'] = '0';
				$totcom = 0.0;
			}

			//Total funds received for current year
			$tmp = $this->db->query('			
					SELECT
						SUM(mrh.amount_paid) AS fundsrec
					FROM ms_reg_history mrh
					WHERE
						mrh.enabled = 1
						AND mrh.year = ' . $this->db->escape($specifiedyear) . '
					');

			if($tmp->num_rows() > 0)
			{											  
				$reginfoarr['fundsrec'] = $tmp->row()->fundsrec;
				$totrec = $tmp->row()->fundsrec;
			}
			else
			{
				$reginfoarr['fundsrec'] = '0';
				$totrec = 0.0;
			}
			
			if ($totreg > 0.0)
				$reginfoarr['perpaid'] = intval(100.0 * $totpaid / $totreg);
			else
				$reginfoarr['perpaid'] = 0;

			if ($totcom > 0.0)
				$reginfoarr['perrec'] = intval(100.0 * $totrec / $totcom);
			else
				$reginfoarr['perrec'] = 0;

			return 	$reginfoarr;		
		}
		
		//Get summary for all registered members for specified year
		public function getRegisteredMembersSummary( $specifiedyear )
		{
			$reginfoarr = array();
			$prevyear = strval($specifiedyear - 1);
						
			//Total registered for current year
			$tmp = $this->db->query('			
					SELECT
						COUNT(crh.household_id_fk) AS totnumreg
					FROM person p
						INNER JOIN household_xref hxr ON hxr.person_id_fk=p.person_id
						INNER JOIN household hh ON hh.household_id=hxr.household_id_fk
						INNER JOIN cmb_reg_history crh ON crh.household_id_fk=hh.household_id
					WHERE
						p.cmb_member=1
						AND p.enabled = 1
						AND crh.enabled=1
						AND hh.enabled = 1
						AND hxr.enabled = 1
						AND crh.year = ' . $this->db->escape($specifiedyear) . '
						AND hxr.member_type = ' . $this->db->escape("Primary") . '
					');

			if($tmp->num_rows() > 0)
			{											  
				$reginfoarr['totnumreg'] = $tmp->row()->totnumreg;
			}
			else
			{
				$reginfoarr['totnumreg'] = '0';
			}
	
			//Total registered from previous year
			$tmp = $this->db->query('			
					SELECT
						COUNT(crh.household_id_fk) AS totnumregprev
					FROM person p
						INNER JOIN household_xref hxr ON hxr.person_id_fk=p.person_id
						INNER JOIN household hh ON hh.household_id=hxr.household_id_fk
						INNER JOIN cmb_reg_history crh ON crh.household_id_fk=hh.household_id
					WHERE
						p.cmb_member=1
						AND p.enabled = 1
						AND crh.enabled=1
						AND hh.enabled = 1
						AND hxr.enabled = 1
						AND crh.year = ' . $this->db->escape($prevyear) . '
						AND hxr.member_type = ' . $this->db->escape("Primary") . '
					');

			if($tmp->num_rows() > 0)
			{											  
				$reginfoarr['totnumregprev'] = $tmp->row()->totnumregprev;
			}
			else
			{
				$reginfoarr['totnumregprev'] = '0';
			}

			//Total registered for current year and paid
			$tmp = $this->db->query('			
					SELECT
						COUNT(crh.household_id_fk) AS regpaid
					FROM person p
						INNER JOIN household_xref hxr ON hxr.person_id_fk=p.person_id
						INNER JOIN household hh ON hh.household_id=hxr.household_id_fk
						INNER JOIN cmb_reg_history crh ON crh.household_id_fk=hh.household_id
					WHERE
						p.cmb_member=1
						AND p.enabled = 1
						AND crh.enabled=1
						AND hh.enabled = 1
						AND hxr.enabled = 1
						AND crh.fully_paid = 1
						AND crh.year = ' . $this->db->escape($specifiedyear) . '
						AND hxr.member_type = ' . $this->db->escape("Primary") . '
					');

			if($tmp->num_rows() > 0)
			{											  
				$reginfoarr['regpaid'] = $tmp->row()->regpaid;
			}
			else
			{
				$reginfoarr['regpaid'] = '0';
			}

			//Total registered current year and paid by CC
			$tmp = $this->db->query('			
					SELECT
						COUNT(crh.household_id_fk) AS regpaidcc
					FROM person p
						INNER JOIN household_xref hxr ON hxr.person_id_fk=p.person_id
						INNER JOIN household hh ON hh.household_id=hxr.household_id_fk
						INNER JOIN cmb_reg_history crh ON crh.household_id_fk=hh.household_id
					WHERE
						p.cmb_member=1
						AND p.enabled = 1
						AND crh.enabled=1
						AND hh.enabled = 1
						AND hxr.enabled = 1
						AND crh.fully_paid = 1
						AND crh.payment_type = ' . $this->db->escape("paypal") . '
						AND crh.year = ' . $this->db->escape($specifiedyear) . '
						AND hxr.member_type = ' . $this->db->escape("Primary") . '
					');

			if($tmp->num_rows() > 0)
			{											  
				$reginfoarr['regpaidcc'] = $tmp->row()->regpaidcc;
			}
			else
			{
				$reginfoarr['regpaidcc'] = '0';
			}

			//Total registered current year and paid by check
			$tmp = $this->db->query('			
					SELECT
						COUNT(crh.household_id_fk) AS regpaidcheck
					FROM person p
						INNER JOIN household_xref hxr ON hxr.person_id_fk=p.person_id
						INNER JOIN household hh ON hh.household_id=hxr.household_id_fk
						INNER JOIN cmb_reg_history crh ON crh.household_id_fk=hh.household_id
					WHERE
						p.cmb_member=1
						AND p.enabled = 1
						AND crh.enabled=1
						AND hh.enabled = 1
						AND hxr.enabled = 1
						AND crh.fully_paid = 1
						AND crh.payment_type = ' . $this->db->escape("check") . '
						AND crh.year = ' . $this->db->escape($specifiedyear) . '
						AND hxr.member_type = ' . $this->db->escape("Primary") . '
					');

			if($tmp->num_rows() > 0)
			{											  
				$reginfoarr['regpaidcheck'] = $tmp->row()->regpaidcheck;
			}
			else
			{
				$reginfoarr['regpaidcheck'] = '0';
			}

			//Total registered current year Life member housholds
			$tmp = $this->db->query('			
					SELECT
						COUNT(crh.household_id_fk) AS reglife
					FROM person p
						INNER JOIN household_xref hxr ON hxr.person_id_fk=p.person_id
						INNER JOIN household hh ON hh.household_id=hxr.household_id_fk
						INNER JOIN cmb_reg_history crh ON crh.household_id_fk=hh.household_id
					WHERE
						p.cmb_member=1
						AND p.enabled = 1
						AND crh.enabled=1
						AND hh.enabled = 1
						AND hxr.enabled = 1
						AND crh.fully_paid = 1
						AND crh.type = ' . $this->db->escape("Life") . '
						AND crh.year = ' . $this->db->escape($specifiedyear) . '
						AND hxr.member_type = ' . $this->db->escape("Primary") . '
					');

			if($tmp->num_rows() > 0)
			{											  
				$reginfoarr['reglife'] = $tmp->row()->reglife;
			}
			else
			{
				$reginfoarr['reglife'] = '0';
			}

			$tmp = $this->db->query('			
					SELECT
						COUNT(crh.cmb_reg_history_id) AS regunpaid
					FROM person p
						INNER JOIN household_xref hxr ON hxr.person_id_fk=p.person_id
						INNER JOIN household hh ON hh.household_id=hxr.household_id_fk
						INNER JOIN cmb_reg_history crh ON crh.household_id_fk=hh.household_id
					WHERE
						p.cmb_member=1
						AND p.enabled = 1
						AND crh.enabled=1
						AND hh.enabled = 1
						AND hxr.enabled = 1
						AND crh.fully_paid = 0
						AND hxr.member_type = ' . $this->db->escape("Primary") . '
						AND crh.year = ' . $this->db->escape($specifiedyear) . '
					');

			if($tmp->num_rows() > 0)
			{											  
				$reginfoarr['regunpaid'] = $tmp->row()->regunpaid;
			}
			else
			{
				$reginfoarr['regunpaid'] = '0';
			}

			$tmp = $this->db->query('			
					SELECT
						COUNT(crh.cmb_reg_history_id) AS regunpaidcheck
					FROM person p
						INNER JOIN household_xref hxr ON hxr.person_id_fk=p.person_id
						INNER JOIN household hh ON hh.household_id=hxr.household_id_fk
						INNER JOIN cmb_reg_history crh ON crh.household_id_fk=hh.household_id
					WHERE
						p.cmb_member=1
						AND p.enabled = 1
						AND crh.enabled=1
						AND hh.enabled = 1
						AND hxr.enabled = 1
						AND crh.fully_paid = 0
						AND hxr.member_type = ' . $this->db->escape("Primary") . '
						AND crh.source = ' . $this->db->escape("offline") . '
						AND crh.payment_type = ' . $this->db->escape("check") . '
						AND crh.year = ' . $this->db->escape($specifiedyear) . '
					');

			if($tmp->num_rows() > 0)
			{											  
				$reginfoarr['regunpaidcheck'] = $tmp->row()->regunpaidcheck;
			}
			else
			{
				$reginfoarr['regunpaidcheck'] = '0';
			}

			$tmp = $this->db->query('			
					SELECT
						COUNT(crh.cmb_reg_history_id) AS regunpaidnp
					FROM person p
						INNER JOIN household_xref hxr ON hxr.person_id_fk=p.person_id
						INNER JOIN household hh ON hh.household_id=hxr.household_id_fk
						INNER JOIN cmb_reg_history crh ON crh.household_id_fk=hh.household_id
					WHERE
						p.cmb_member=1
						AND p.enabled = 1
						AND crh.enabled=1
						AND hh.enabled = 1
						AND hxr.enabled = 1
						AND crh.fully_paid = 0
						AND hxr.member_type = ' . $this->db->escape("Primary") . '
						AND crh.source <> ' . $this->db->escape("offline") . '
						AND crh.obj_temp_id > 0
						AND crh.year = ' . $this->db->escape($specifiedyear) . '
					');

			if($tmp->num_rows() > 0)
			{											  
				$reginfoarr['regunpaidnp'] = $tmp->row()->regunpaidnp;
			}
			else
			{
				$reginfoarr['regunpaidnp'] = '0';
			}

			$tmp = $this->db->query('			
					SELECT
						COUNT(crh.cmb_reg_history_id) AS newreg
						FROM person p
						INNER JOIN household_xref hxr ON hxr.person_id_fk=p.person_id
						INNER JOIN household hh ON hh.household_id=hxr.household_id_fk
						INNER JOIN cmb_reg_history crh ON crh.household_id_fk=hh.household_id
					WHERE
						p.cmb_member = 1
						AND p.enabled = 1
						AND crh.enabled = 1
						AND hxr.enabled = 1
						AND hh.enabled = 1
						AND p.first_name <> ' . $this->db->escape("Admin") . '
						AND hxr.member_type = ' . $this->db->escape("Primary") . '
						AND crh.year = ' . $this->db->escape($specifiedyear) . '
						AND	crh.household_id_fk NOT IN (
						SELECT
						crh.household_id_fk
						FROM person p
						INNER JOIN household_xref hxr ON hxr.person_id_fk=p.person_id
						INNER JOIN household hh ON hh.household_id=hxr.household_id_fk
						INNER JOIN cmb_reg_history crh ON crh.household_id_fk=hh.household_id
						WHERE
						p.cmb_member = 1
						AND p.enabled = 1
						AND crh.enabled = 1
						AND hxr.enabled = 1
						AND hh.enabled = 1
						AND crh.year = ' . $this->db->escape($prevyear) . '
						AND p.first_name <> ' . $this->db->escape("Admin") . '
						AND hxr.member_type = ' . $this->db->escape("Primary") . ')
					');

			if($tmp->num_rows() > 0)
			{											  
				$reginfoarr['newreg'] = $tmp->row()->newreg;
			}
			else
			{
				$reginfoarr['newreg'] = '0';
			}
/*
			$tmp = $this->db->query('			
					SELECT
						COUNT(crh.cmb_reg_history_id) AS regprevyr
						FROM person p
						INNER JOIN household_xref hxr ON hxr.person_id_fk=p.person_id
						INNER JOIN household hh ON hh.household_id=hxr.household_id_fk
						INNER JOIN cmb_reg_history crh ON crh.household_id_fk=hh.household_id
					WHERE
						p.cmb_member = 1
						AND p.enabled = 1
						AND crh.enabled = 1
						AND p.first_name <> ' . $this->db->escape("Admin") . '
						AND hxr.member_type = ' . $this->db->escape("Primary") . '
						AND crh.year = ' . $this->db->escape($prevyear) . ';
					');
*/
			$tmp = $this->db->query('			
					SELECT
						COUNT(crh.cmb_reg_history_id) AS unreg
						FROM person p
						INNER JOIN household_xref hxr ON hxr.person_id_fk=p.person_id
						INNER JOIN household hh ON hh.household_id=hxr.household_id_fk
						INNER JOIN cmb_reg_history crh ON crh.household_id_fk=hh.household_id
					WHERE
						p.cmb_member = 1
						AND p.enabled = 1
						AND crh.enabled = 1
						AND hxr.enabled = 1
						AND hh.enabled = 1
						AND p.first_name <> ' . $this->db->escape("Admin") . '
						AND hxr.member_type = ' . $this->db->escape("Primary") . '
						AND crh.year = ' . $this->db->escape($prevyear) . '
						AND	crh.household_id_fk NOT IN (
						SELECT
						crh.household_id_fk
						FROM person p
						INNER JOIN household_xref hxr ON hxr.person_id_fk=p.person_id
						INNER JOIN household hh ON hh.household_id=hxr.household_id_fk
						INNER JOIN cmb_reg_history crh ON crh.household_id_fk=hh.household_id
						WHERE
						p.cmb_member = 1
						AND p.enabled = 1
						AND crh.enabled = 1
						AND hxr.enabled = 1
						AND hh.enabled = 1
						AND crh.year = ' . $this->db->escape($specifiedyear) . '
						AND p.first_name <> ' . $this->db->escape("Admin") . '
						AND hxr.member_type = ' . $this->db->escape("Primary") . ')
					');

			if($tmp->num_rows() > 0)
			{											  
				//$reginfoarr['remreg'] = $tmp->row()->regprevyr - $reginfoarr['totnumreg'] + $reginfoarr['newreg'];
				$reginfoarr['remreg'] = $tmp->row()->unreg;
			}
			else
			{
				$reginfoarr['remreg'] = '0';
			}

			$tmp = $this->db->query('			
					SELECT
						SUM(crh.amount_paid*crh.fully_paid) AS fundsrec,
						SUM(crh.registration_amount+crh.donation_amount+crh.bv_amount) AS fundscom,
						ROUND(100.0*SUM(crh.amount_paid*crh.fully_paid)/SUM(crh.registration_amount+crh.donation_amount+crh.bv_amount)) AS perpaid
					FROM person p
						INNER JOIN household_xref hxr ON hxr.person_id_fk=p.person_id
						INNER JOIN household hh ON hh.household_id=hxr.household_id_fk
						INNER JOIN cmb_reg_history crh ON crh.household_id_fk=hh.household_id
					WHERE
						p.cmb_member=1
						AND p.enabled = 1
						AND crh.enabled=1
						AND hh.enabled = 1
						AND hxr.enabled = 1
						AND hxr.member_type = ' . $this->db->escape("Primary") . '
						AND crh.year = ' . $this->db->escape($specifiedyear) . '
					');

			if($tmp->num_rows() > 0)
			{											  
				$reginfoarr['fundscom'] = number_format(floatval($tmp->row()->fundscom),2,'.',',');
				$reginfoarr['fundsrec'] = number_format(floatval($tmp->row()->fundsrec),2,'.',',');
				$reginfoarr['perpaid'] = $tmp->row()->perpaid;
			}
			else
			{
				$reginfoarr['fundscom'] = '0';
				$reginfoarr['fundsrec'] = '0';
				$reginfoarr['perpaid'] = '0';
			}

			return 	$reginfoarr;		
		}

		//Get all registered members for specified year
		public function getRegisteredMembers( $specifiedyear, $searchcriteria )
		{
			$reginfoarr = array();
						
			$searchstr = " ";
			if (!empty($searchcriteria['memberlastname']))
				$searchstr = " AND p.last_name LIKE '".$searchcriteria['memberlastname']."%' ";
			
			if (!empty($searchcriteria['memberfirstname']))
				$searchstr = $searchstr."AND p.first_name LIKE '".$searchcriteria['memberfirstname']."%' ";

			if (!empty($searchcriteria['membercity']))
				$searchstr = $searchstr."AND p.city LIKE '".$searchcriteria['membercity']."%' ";

			if ((!empty($searchcriteria['memberstate'])) and ($searchcriteria['memberstate'] != "All"))
				$searchstr = $searchstr."AND p.state = '".$searchcriteria['memberstate']."' ";

			if ((!empty($searchcriteria['centername'])) and ($searchcriteria['centername'] != "All"))
				$searchstr = $searchstr."AND cc.center_name = '".$searchcriteria['centername']."' ";

			$tmp = $this->db->query('			
					SELECT
						p.first_name,
						IFNULL(p.last_name,' . $this->db->escape("") . ') AS last_name,
						IFNULL(p.phone1,' . $this->db->escape("") . ') AS phone,
						IFNULL(p.email1,' . $this->db->escape("") . ') AS email,
						IFNULL(p.address1,' . $this->db->escape("") . ') AS address,
						IFNULL(p.city,' . $this->db->escape("") . ') AS city,
						IFNULL(p.state,' . $this->db->escape("") . ') AS state,
						IFNULL(p.zip,' . $this->db->escape("") . ') AS zip,
						cc.center_name
						FROM person p
						INNER JOIN household_xref hxr ON hxr.person_id_fk=p.person_id
						INNER JOIN household hh ON hh.household_id=hxr.household_id_fk
						INNER JOIN cmb_reg_history crh ON crh.household_id_fk=hh.household_id
						INNER JOIN cmb_center cc ON cc.cmb_center_id=crh.cmb_center_id_fk
					WHERE
						p.cmb_member = 1
						AND p.enabled = 1
						AND hxr.enabled = 1
						AND hh.enabled = 1
						AND hxr.member_type = ' . $this->db->escape("Primary") . '
						AND crh.year = ' . $this->db->escape($specifiedyear) . $searchstr .
					'ORDER BY p.last_name ASC;
					');

			if($tmp->num_rows() > 0)
			{											  
				foreach ($tmp->result() as $regRow)
				{
					$regrec = array();
					
					$regrec['firstname'] = $regRow->first_name;
					$regrec['lastname'] = $regRow->last_name;
					$regrec['phone'] = $regRow->phone;
					$regrec['email'] = $regRow->email;
					$regrec['address'] = $regRow->address;
					$regrec['city'] = $regRow->city;
					$regrec['state'] = $regRow->state;
					$regrec['zip'] = $regRow->zip;
					$regrec['center_name'] = $regRow->center_name;					

					array_push($reginfoarr, $regrec);
				}
			}
	
			return 	$reginfoarr;		
		}
		
		//Get registered members for specified search criteria and year for Admin use
		public function getRegisteredMembersAdmin( $specifiedyear, $searchcriteria )
		{
			$reginfoarr = array();
						
			$searchstr = " ";
			if (!empty($searchcriteria['memberlastname']))
				$searchstr = " AND p.last_name LIKE '".$searchcriteria['memberlastname']."%' ";
			
			if (!empty($searchcriteria['memberfirstname']))
				$searchstr = $searchstr."AND p.first_name LIKE '".$searchcriteria['memberfirstname']."%' ";

			if (!empty($searchcriteria['membercity']))
				$searchstr = $searchstr."AND p.city LIKE '".$searchcriteria['membercity']."%' ";

			if ((!empty($searchcriteria['memberstate'])) and ($searchcriteria['memberstate'] != "All"))
				$searchstr = $searchstr."AND p.state = '".$searchcriteria['memberstate']."' ";

			if ((!empty($searchcriteria['centername'])) and ($searchcriteria['centername'] != "All"))
				$searchstr = $searchstr."AND cc.center_name = '".$searchcriteria['centername']."' ";

			if ((!empty($searchcriteria['paid'])) and ($searchcriteria['paid'] != "All"))
			{
				if ($searchcriteria['paid'] == "Paid")
					$searchstr = $searchstr."AND crh.fully_paid = 1 ";
				else
					$searchstr = $searchstr."AND crh.fully_paid = 0 ";
			}

			if ((!empty($searchcriteria['memtype'])) and ($searchcriteria['memtype'] != "All"))
			{
				if ($searchcriteria['memtype'] == "Life")
					$searchstr = $searchstr."AND crh.type = 'Life' ";
				else
					$searchstr = $searchstr."AND crh.type = 'Regular' ";
			}

			if ((!empty($searchcriteria['paytype'])) and ($searchcriteria['paytype'] != "All"))
			{
				if ($searchcriteria['paytype'] == "Online")
					$searchstr = $searchstr."AND crh.payment_type = 'paypal'";

				if ($searchcriteria['paytype'] == "Check")
					$searchstr = $searchstr."AND crh.payment_type = 'check'";
				
				if ($searchcriteria['paytype'] == "None")
					$searchstr = $searchstr."AND ((crh.payment_type = 'unknown') OR (crh.payment_type = 'na')) ";
			}

			$tmp = $this->db->query('			
					SELECT
						p.first_name,
						IFNULL(p.last_name,' . $this->db->escape("") . ') AS last_name,
						IFNULL(p.phone1,' . $this->db->escape("") . ') AS phone,
						IFNULL(p.email1,' . $this->db->escape("") . ') AS email,
						IFNULL(p.address1,' . $this->db->escape("") . ') AS address,
						IFNULL(p.city,' . $this->db->escape("") . ') AS city,
						IFNULL(p.state,' . $this->db->escape("") . ') AS state,
						IFNULL(p.zip,' . $this->db->escape("") . ') AS zip,
						cc.center_name,
						crh.type,
						crh.session,
						crh.amount_paid,
						crh.payment_type,
						crh.fully_paid
					FROM person p
						INNER JOIN household_xref hxr ON hxr.person_id_fk=p.person_id
						INNER JOIN household hh ON hh.household_id=hxr.household_id_fk
						INNER JOIN cmb_reg_history crh ON crh.household_id_fk=hh.household_id
						INNER JOIN cmb_center cc ON cc.cmb_center_id=crh.cmb_center_id_fk
					WHERE
						p.cmb_member = 1
						AND p.enabled = 1
						AND hxr.enabled = 1
						AND hh.enabled = 1
						AND hxr.member_type = ' . $this->db->escape("Primary") . '
						AND crh.year = ' . $this->db->escape($specifiedyear) . $searchstr .
					'ORDER BY p.last_name ASC;
					');

			if($tmp->num_rows() > 0)
			{											  
				foreach ($tmp->result() as $regRow)
				{
					$regrec = array();
					
					$regrec['firstname'] = $regRow->first_name;
					$regrec['lastname'] = $regRow->last_name;
					$regrec['phone'] = $regRow->phone;
					$regrec['email'] = $regRow->email;
					$regrec['address'] = $regRow->address;
					$regrec['city'] = $regRow->city;
					$regrec['state'] = $regRow->state;
					$regrec['zip'] = $regRow->zip;
					$regrec['type'] = $regRow->type;
					$regrec['session'] = $regRow->session;
					$regrec['amount_paid'] = $regRow->amount_paid;
					$regrec['payment_type'] = $regRow->payment_type;
					$regrec['center_name'] = $regRow->center_name;
					if ($regRow->fully_paid == 1)
						$regrec['fully_paid'] = "Paid";	
					else
						$regrec['fully_paid'] = "Not Paid";			

					array_push($reginfoarr, $regrec);
				}
			}
	
			return 	$reginfoarr;		
		}		

		//Get all registered households for specified year for Admin use
		public function getRegisteredHouseholdsAdmin( $specifiedyear )
		{
			$tmp = $this->db->query('			
					SELECT
						hxr.household_id_fk
					FROM person p
						INNER JOIN household_xref hxr ON hxr.person_id_fk=p.person_id
						INNER JOIN household hh ON hh.household_id=hxr.household_id_fk
						INNER JOIN cmb_reg_history crh ON crh.household_id_fk=hh.household_id
					WHERE
						p.cmb_member = 1
						AND p.enabled = 1
						AND crh.enabled = 1
						AND hxr.enabled = 1
						AND hh.enabled = 1
						AND crh.year = ' . $this->db->escape($specifiedyear) . '
						AND p.first_name <> ' . $this->db->escape("Admin") . '
						AND hxr.member_type = ' . $this->db->escape("Primary") . '
					ORDER BY p.last_name ASC;					
			');

			$hhidarr = array();
			if($tmp->num_rows() > 0)
			{											  
				foreach ($tmp->result() as $hhid)
				{
					array_push($hhidarr, $hhid->household_id_fk);
				}
			}
	
			return 	$hhidarr;		
		}		

		//Get all unregistered households for specified year for Admin use
		public function getUnregisteredHouseholdsAdmin( $specifiedyear )
		{
			$tmp = $this->db->query('			
					SELECT
						hxr.household_id_fk
					FROM person p
						INNER JOIN household_xref hxr ON hxr.person_id_fk=p.person_id
						INNER JOIN household hh ON hh.household_id=hxr.household_id_fk
						INNER JOIN cmb_reg_history crh ON crh.household_id_fk=hh.household_id
					WHERE
						p.cmb_member = 1
						AND p.enabled = 1
						AND crh.enabled = 1
						AND hxr.enabled = 1
						AND hh.enabled = 1
						AND crh.year = ' . $this->db->escape($specifiedyear-1) . '
						AND p.first_name <> ' . $this->db->escape("Admin") . '
						AND hxr.member_type = ' . $this->db->escape("Primary") . '
						AND crh.household_id_fk NOT IN
							(SELECT
								crh1.household_id_fk
							FROM person p1
								INNER JOIN household_xref hxr1 ON hxr1.person_id_fk=p1.person_id
								INNER JOIN household hh1 ON hh1.household_id=hxr1.household_id_fk
								INNER JOIN cmb_reg_history crh1 ON crh1.household_id_fk=hh1.household_id
							WHERE
								p1.cmb_member = 1
								AND p1.enabled = 1
								AND crh.enabled = 1
								AND hxr1.enabled = 1
								AND hh1.enabled = 1
								AND crh1.year = ' . $this->db->escape($specifiedyear) . '
								AND p1.first_name <> ' . $this->db->escape("Admin") . '
								AND hxr1.member_type=' . $this->db->escape("Primary") . ')
					ORDER BY p.last_name ASC;					
			');

			$hhidarr = array();
			if($tmp->num_rows() > 0)
			{											  
				foreach ($tmp->result() as $hhid)
				{
					array_push($hhidarr, $hhid->household_id_fk);
				}
			}
	
			return 	$hhidarr;		
		}		

		//Get all household info for specified household for Admin use
		public function getHouseholdInfoAdmin( $hh_id_arr, $specifiedyear )
		{
			$householdinfo = array();
			
			foreach($hh_id_arr as $hhid)
			{
				$householdarr = array();
				
				$tmp = $this->db->query('			
						SELECT
							crh.cmb_reg_history_id AS ' . $this->db->escape("reg_id") . ',
							hh.household_id AS ' . $this->db->escape("HH_ID") . ',
							hxr.member_type AS ' . $this->db->escape("type") . ',
							CONCAT_WS(' . $this->db->escape(" ") . ',p.first_name,IFNULL(p.last_name,' . $this->db->escape("") . ')) AS ' . $this->db->escape("name") . ',
							p.gender AS ' . $this->db->escape("gender") . ',
							IFNULL(p.email1,' . $this->db->escape("") . ') AS ' . $this->db->escape("email") . ',
							IFNULL(p.phone1,' . $this->db->escape("") . ') AS ' . $this->db->escape("phone1") . ',
							IFNULL(p.phone2,' . $this->db->escape("") . ') AS ' . $this->db->escape("phone2") . ',
							IFNULL(p.address1,' . $this->db->escape("") . ') AS ' . $this->db->escape("address") . ',
							IFNULL(p.city,' . $this->db->escape("") . ') AS ' . $this->db->escape("city") . ',
							IFNULL(p.state,' . $this->db->escape("") . ') AS ' . $this->db->escape("state") . ',
							IFNULL(p.zip,' . $this->db->escape("") . ') AS ' . $this->db->escape("zip") . ',
							IFNULL(DATE_FORMAT(p.birth_date,' . $this->db->escape("%d-%M-%Y") . '),' . $this->db->escape("") . ') AS ' . $this->db->escape("dob") . ',
							crh.session AS ' . $this->db->escape("session") . ',
							IFNULL(brh.grade,' . $this->db->escape("") . ') AS ' . $this->db->escape("grade") . ',
							crh.obj_temp_id,
							crh.payment_type,
							crh.fully_paid,
							IFNULL(l.language_name,' . $this->db->escape("") . ') AS ' . $this->db->escape("language_name") . ',
							IFNULL(lrh.level,' . $this->db->escape("") . ') AS ' . $this->db->escape("level") . '
						FROM person p
							INNER JOIN household_xref hxr ON hxr.person_id_fk=p.person_id
							INNER JOIN household hh ON hh.household_id=hxr.household_id_fk
							INNER JOIN cmb_reg_history crh ON crh.household_id_fk=hh.household_id
							LEFT OUTER JOIN bv_reg_history brh ON brh.person_id_fk=p.person_id AND brh.year = ' . $this->db->escape($specifiedyear) . '
							LEFT OUTER JOIN lang_reg_history lrh ON lrh.person_id_fk=p.person_id AND lrh.year = ' . $this->db->escape($specifiedyear) . '
							LEFT OUTER JOIN language l ON l.language_id=lrh.language_id_fk
						WHERE
							p.cmb_member = 1
							AND p.enabled = 1
							AND crh.enabled = 1
							AND hxr.enabled = 1
							AND hh.enabled = 1
							AND crh.year = ' . $this->db->escape($specifiedyear) . '
							AND hxr.household_id_fk = ' . $this->db->escape($hhid) . '
						GROUP BY p.person_id;
				');

				$householdarr = array();
				if($tmp->num_rows() > 0)
				{														
					foreach ($tmp->result() as $pid)
					{
						$hhrecarr = array();
						
						array_push($hhrecarr, $pid->HH_ID); //(0)
						array_push($hhrecarr, $pid->reg_id); //(1)
						array_push($hhrecarr, $pid->type);
						array_push($hhrecarr, $pid->name);
						array_push($hhrecarr, $pid->gender);
						array_push($hhrecarr, $pid->session);				
						array_push($hhrecarr, $pid->email); //(6)
						array_push($hhrecarr, $pid->phone1);
						array_push($hhrecarr, $pid->phone2);
						array_push($hhrecarr, $pid->address); //(9)
						array_push($hhrecarr, $pid->city);
						array_push($hhrecarr, $pid->state);
						array_push($hhrecarr, strval($pid->zip));
						array_push($hhrecarr, strval($pid->dob)); //(13)
						array_push($hhrecarr, strval($pid->grade));
						array_push($hhrecarr, strval($pid->obj_temp_id));
						array_push($hhrecarr, strval($pid->payment_type));
						if ($pid->fully_paid == 1)
							array_push($hhrecarr, "Paid");
						else
						{
							if ($pid->payment_type == "check")
								array_push($hhrecarr, "Waiting for Check");
							else
								array_push($hhrecarr, "Unpaid");
						}
						
						array_push($hhrecarr, strval($pid->language_name)); //(18)
						array_push($hhrecarr, strval($pid->level));
													
						array_push($householdarr, $hhrecarr);
					}
					
					array_push($householdinfo, $householdarr);
				}
			}
	
			return 	$householdinfo;		
		}		

		//Get Balavihar Admin data for a specified year
		public function getBalaviharAdminData( $specifiedyear, $searchcriteria )
		{
			$bvinfoarr = array();
						
			$searchstr = " ";
			if (!empty($searchcriteria['memberlastname']))
				$searchstr = " AND p.last_name LIKE '".$searchcriteria['memberlastname']."%' ";
			
			if (!empty($searchcriteria['memberfirstname']))
				$searchstr = $searchstr."AND p.first_name LIKE '".$searchcriteria['memberfirstname']."%' ";

			if (!empty($searchcriteria['membercity']))
				$searchstr = $searchstr."AND p.city LIKE '".$searchcriteria['membercity']."%' ";

			if ((!empty($searchcriteria['memberstate'])) and ($searchcriteria['memberstate'] != "All"))
				$searchstr = $searchstr."AND p.state = '".$searchcriteria['memberstate']."' ";

			if ((!empty($searchcriteria['centername'])) and ($searchcriteria['centername'] != "All"))
				$searchstr = $searchstr."AND cc.center_name = '".$searchcriteria['centername']."' ";

			if ((!empty($searchcriteria['session'])) and ($searchcriteria['session'] != "All"))
				$searchstr = $searchstr."AND brh.session = '".$searchcriteria['session']."' ";

			if ((!empty($searchcriteria['gradename'])) and ($searchcriteria['gradename'] != "All"))
				$searchstr = $searchstr."AND brh.grade = '".$searchcriteria['gradename']."' ";

			$tmp = $this->db->query('			
					SELECT
						p.first_name,
						IFNULL(p.last_name,' . $this->db->escape("") . ') AS last_name,
						brh.grade,
						brh.session,
						cc.center_name,
						IFNULL(p.city,' . $this->db->escape("") . ') AS city,
						IFNULL(p.state,' . $this->db->escape("") . ') AS state,
						IFNULL(DATE_FORMAT(p.birth_date,' . $this->db->escape("%d-%M-%Y") . '),' . $this->db->escape("") . ') AS birth_date						
					FROM bv_reg_history brh
						INNER JOIN person p ON p.person_id = brh.person_id_fk
						INNER JOIN grade g ON g.grade_name = brh.grade
						INNER JOIN cmb_center cc ON cc.cmb_center_id=brh.cmb_center_id_fk
					WHERE
						p.cmb_member = 1
						AND p.enabled = 1
						AND brh.enabled = 1
						AND brh.year = ' . $this->db->escape($specifiedyear) . $searchstr .
					'ORDER BY g.grade_id ASC, brh.session ASC, p.last_name ASC;
					');

			if($tmp->num_rows() > 0)
			{											  
				foreach ($tmp->result() as $bvRow)
				{
					$bvrec = array();
					
					$bvrec['firstname'] = $bvRow->first_name;
					$bvrec['lastname'] = $bvRow->last_name;
					$bvrec['gradename'] = $bvRow->grade;
					$bvrec['session'] = $bvRow->session;
					$bvrec['centername'] = $bvRow->center_name;
					$bvrec['city'] = $bvRow->city;
					$bvrec['state'] = $bvRow->state;

					array_push($bvinfoarr, $bvrec);
				}
			}
	
			return 	$bvinfoarr;		
		}		
		
        //Get Balavihar class assignment information for a specified year and sepcific criteria
        public function getBalaviharSpecificClassAssignmentData( $specifiedyear, $centername, $session, $gradename, $status )
        {
            $bvinfoarr = array();
            $arridx = array();
            $bvinfoarrsrt = array();
                        
            $searchstr = " ";

            if (($centername != "") && ($centername != "All"))
                $searchstr = $searchstr."AND cc.center_name = '".$centername."' ";

            if (($session != "") && ($session != "All"))
                $searchstr = $searchstr."AND brh.session = '".$session."' ";

            $grade = $gradename;

            if ($grade != "Pre-K")
            {
                if ($grade == "K")
                    $prevgrade = "Pre-K";
                else
                {
                    if ($grade == "1")
                        $prevgrade = "K";
                    else
                        $prevgrade = strval(intval($grade)-1);
                }
        
                $searchstrgrd = "AND brh.grade = '".$prevgrade."' ";
                $searchstrfin = $searchstr.$searchstrgrd;
                
                $searchstr1 = " ";

                if (($centername != "") && ($centername != "All"))
                    $searchstr1 = $searchstr1."AND cc1.center_name = '".$centername."' ";
    
                if (($session != "") && ($session != "All"))
                    $searchstr1 = $searchstr1."AND brh1.session = '".$session."' ";

                //Get all unregistered members from previous year
                $searchstrgrd1 = "AND brh1.grade = '".$grade."' ";
                $searchstrfin1 = $searchstr1.$searchstrgrd1;

                if (($status == "All") || ($status == "Unregistered"))
                {
                    $tmp = $this->db->query('           
                            SELECT
                                brh.person_id_fk,
                                p.first_name,
                                IFNULL(p.last_name,' . $this->db->escape("") . ') AS last_name,
                                brh.grade,
                                brh.session,
                                cc.center_name,
                                IFNULL(p.city,' . $this->db->escape("") . ') AS city,
                                IFNULL(p.state,' . $this->db->escape("") . ') AS state,
                                crh.fully_paid,
                                (SELECT p1.phone1 FROM household_xref hxr1 INNER JOIN person p1 ON p1.person_id=hxr1.person_id_fk WHERE p1.enabled=1 AND p1.cmb_member=1 AND hxr1.household_id_fk=hh.household_id AND hxr1.member_type=' . $this->db->escape("Primary") . ' GROUP BY p1.person_id) AS parent_phone,
                                IFNULL(p.email1,' . $this->db->escape("") . ') AS child_email,                  
                                (SELECT p1.email1 FROM household_xref hxr1 INNER JOIN person p1 ON p1.person_id=hxr1.person_id_fk WHERE p1.enabled=1 AND p1.cmb_member=1 AND hxr1.household_id_fk=hh.household_id AND hxr1.member_type=' . $this->db->escape("Primary") . ' GROUP BY p1.person_id) AS parent_email,
                                (SELECT CONCAT_WS(' . $this->db->escape(" ") . ',IFNULL(p1.first_name,' . $this->db->escape("") . '),IFNULL(p1.last_name,' . $this->db->escape("") . ')) FROM household_xref hxr1 INNER JOIN person p1 ON p1.person_id=hxr1.person_id_fk WHERE p1.enabled=1 AND p1.cmb_member=1 AND hxr1.household_id_fk=hh.household_id AND hxr1.member_type=' . $this->db->escape("Primary") . ' GROUP BY p1.person_id) AS parent_name,
                                IFNULL(DATE_FORMAT(p.birth_date,' . $this->db->escape("%m/%d/%y") . '),' . $this->db->escape("") . ') AS birth_date,
                                hh.household_id
                            FROM bv_reg_history brh
                                INNER JOIN person p ON p.person_id = brh.person_id_fk
                                INNER JOIN household_xref hxr ON hxr.person_id_fk=p.person_id
                                INNER JOIN household hh ON hh.household_id=hxr.household_id_fk
                                INNER JOIN cmb_reg_history crh ON crh.household_id_fk=hh.household_id AND crh.year = ' . $this->db->escape($specifiedyear-1) . '
                                INNER JOIN grade g ON g.grade_name = brh.grade
                                INNER JOIN cmb_center cc ON cc.cmb_center_id=brh.cmb_center_id_fk
                            WHERE
                                p.cmb_member = 1
                                AND p.enabled = 1
                                AND brh.enabled = 1
                                AND hxr.enabled = 1
                                AND hh.enabled = 1
                                AND brh.year = ' . $this->db->escape($specifiedyear-1) . $searchstrfin . '
                                AND brh.person_id_fk NOT IN
                                (
                                    SELECT
                                        brh1.person_id_fk
                                    FROM bv_reg_history brh1
                                        INNER JOIN person p1 ON p1.person_id = brh1.person_id_fk
                                        INNER JOIN household_xref hxr1 ON hxr1.person_id_fk=p1.person_id
                                        INNER JOIN household hh1 ON hh1.household_id=hxr1.household_id_fk
                                        INNER JOIN cmb_reg_history crh1 ON crh1.household_id_fk=hh1.household_id AND crh1.year = ' . $this->db->escape($specifiedyear) . '
                                        INNER JOIN grade g1 ON g1.grade_name = brh1.grade
                                        INNER JOIN cmb_center cc1 ON cc1.cmb_center_id=brh1.cmb_center_id_fk
                                    WHERE
                                        p1.cmb_member = 1
                                        AND p1.enabled = 1
                                        AND brh1.enabled = 1
                                        AND hxr1.enabled = 1
                                        AND hh1.enabled = 1
                                        AND brh1.year = ' . $this->db->escape($specifiedyear) . $searchstrfin1 . '
                                )
                            GROUP BY p.person_id
                            ORDER BY brh.session ASC, g.grade_id ASC, p.last_name ASC;
                            ');
        
                    if($tmp->num_rows() > 0)
                    {                                             
                        foreach ($tmp->result() as $bvRow)
                        {
                            $bvrec = array();
                            
                            $bvrec['firstname'] = $bvRow->first_name;
                            $bvrec['lastname'] = $bvRow->last_name;
                            //$bvrec['gradename'] = $bvRow->grade;
                            $bvrec['gradename'] = $grade;
                            $bvrec['session'] = $bvRow->session;
                            $bvrec['centername'] = $bvRow->center_name;
                            $bvrec['city'] = $bvRow->city;
                            $bvrec['state'] = $bvRow->state;                        
                            $bvrec['fully_paid'] = "Unregistered";                          
                            //$bvrec['teacher_group_id'] = $bvRow->teacher_group_id;
                            $bvrec['child_email'] = $bvRow->child_email;
                            $bvrec['parent_phone'] = $bvRow->parent_phone;
                            $bvrec['parent_email'] = $bvRow->parent_email;
                            $bvrec['birth_date'] = $bvRow->birth_date;
                            $bvrec['household_id'] = $bvRow->household_id;
                            $bvrec['parent_name'] = $bvRow->parent_name;
                            $bvrec['language'] = "n/a"; 
        
                            array_push($bvinfoarr, $bvrec);
                            array_push($arridx,strtolower($bvRow->last_name));
                            
                            unset($bvrec);
                        }
                    }
                }
            }
            else
                $prevgrade = $grade;
                
            //Get all registrants for current year
            $searchstrgrd = "AND brh.grade = '".$grade."' ";
            $searchstrfin = $searchstr.$searchstrgrd;
            
            if (($status == "All") || ($status == "Registered"))
            {
                $tmp = $this->db->query('           
                        SELECT
                            brh.person_id_fk,
                            p.first_name,
                            IFNULL(p.last_name,' . $this->db->escape("") . ') AS last_name,
                            brh.grade,
                            brh.session,
                            cc.center_name,
                            IFNULL(p.city,' . $this->db->escape("") . ') AS city,
                            IFNULL(p.state,' . $this->db->escape("") . ') AS state,
                            crh.fully_paid,
                            (SELECT p1.phone1 FROM household_xref hxr1 INNER JOIN person p1 ON p1.person_id=hxr1.person_id_fk WHERE p1.enabled=1 AND p1.cmb_member=1 AND hxr1.household_id_fk=hh.household_id AND hxr1.member_type=' . $this->db->escape("Primary") . ' GROUP BY p1.person_id) AS parent_phone,
                            IFNULL(p.email1,' . $this->db->escape("") . ') AS child_email,                  
                            (SELECT p1.email1 FROM household_xref hxr1 INNER JOIN person p1 ON p1.person_id=hxr1.person_id_fk WHERE p1.enabled=1 AND p1.cmb_member=1 AND hxr1.household_id_fk=hh.household_id AND hxr1.member_type=' . $this->db->escape("Primary") . ' GROUP BY p1.person_id) AS parent_email,
                            (SELECT CONCAT_WS(' . $this->db->escape(" ") . ',IFNULL(p1.first_name,' . $this->db->escape("") . '),IFNULL(p1.last_name,' . $this->db->escape("") . ')) FROM household_xref hxr1 INNER JOIN person p1 ON p1.person_id=hxr1.person_id_fk WHERE p1.enabled=1 AND p1.cmb_member=1 AND hxr1.household_id_fk=hh.household_id AND hxr1.member_type=' . $this->db->escape("Primary") . ' GROUP BY p1.person_id) AS parent_name,
                            IFNULL(DATE_FORMAT(p.birth_date,' . $this->db->escape("%m/%d/%y") . '),' . $this->db->escape("") . ') AS birth_date,
                            IFNULL(lng.language_name,' . $this->db->escape("n/a") . ') AS language,
                            hh.household_id
                        FROM bv_reg_history brh
                            INNER JOIN person p ON p.person_id = brh.person_id_fk
                            INNER JOIN household_xref hxr ON hxr.person_id_fk=p.person_id
                            INNER JOIN household hh ON hh.household_id=hxr.household_id_fk
                            INNER JOIN cmb_reg_history crh ON crh.household_id_fk=hh.household_id AND crh.year = ' . $this->db->escape($specifiedyear) . '
                            INNER JOIN grade g ON g.grade_name = brh.grade
                            INNER JOIN cmb_center cc ON cc.cmb_center_id=brh.cmb_center_id_fk
                            LEFT OUTER JOIN lang_reg_history lrh ON lrh.person_id_fk=brh.person_id_fk AND lrh.year = ' . $this->db->escape($specifiedyear) . '
                            LEFT OUTER JOIN language lng ON lng.language_id=lrh.language_id_fk
                        WHERE
                            p.cmb_member = 1
                            AND p.enabled = 1
                            AND brh.enabled = 1
                            AND hxr.enabled = 1
                            AND hh.enabled = 1
                            AND brh.year = ' . $this->db->escape($specifiedyear) . $searchstrfin . '
                        GROUP BY p.person_id
                        ORDER BY brh.session ASC, g.grade_id ASC, p.last_name ASC;
                        ');

                if($tmp->num_rows() > 0)
                {                                             
                    foreach ($tmp->result() as $bvRow)
                    {
                        $bvrec = array();
                        
                        $bvrec['firstname'] = $bvRow->first_name;
                        $bvrec['lastname'] = $bvRow->last_name;
                        $bvrec['gradename'] = $bvRow->grade;
                        $bvrec['session'] = $bvRow->session;
                        $bvrec['centername'] = $bvRow->center_name;
                        $bvrec['city'] = $bvRow->city;
                        $bvrec['state'] = $bvRow->state;
                        
                        if ($bvRow->fully_paid == 1)
                            $bvrec['fully_paid'] = "Registered-Paid";
                        else
                            $bvrec['fully_paid'] = "Registered-Unpaid";
                            
                        $bvrec['child_email'] = $bvRow->child_email;
                        $bvrec['parent_phone'] = $bvRow->parent_phone;
                        $bvrec['parent_email'] = $bvRow->parent_email;
                        $bvrec['birth_date'] = $bvRow->birth_date;
                        $bvrec['household_id'] = $bvRow->household_id;
                        $bvrec['parent_name'] = $bvRow->parent_name;
                        $bvrec['language'] = $bvRow->language;
    
                        array_push($bvinfoarr, $bvrec);
                        array_push($arridx,strtolower($bvRow->last_name));
                    }
                }
            }
    
            if (count($arridx) > 0)
            {
                //Sort by last_name
                asort($arridx);
                
                foreach ($arridx as $key => $val)
                {
                    $idx = intval($key);
                    $tmprec = $bvinfoarr[$idx];
                    array_push($bvinfoarrsrt, $tmprec);
                    //echo $tmprec[0].",".$tmprec[1].",".$tmprec[2].",".$tmprec[3].",".$tmprec[4]."</br>";
                }       
                
                unset($bvinfoarr);
                unset($arridx);
            }

            return  $bvinfoarrsrt;      
        }       
        
		//Get Balavihar class assignment information for a specified year and search criteria
		public function getBalaviharClassAssignmentData( $specifiedyear, $searchcriteria )
		{
			$bvinfoarr = array();
			$arridx = array();
			$bvinfoarrsrt = array();
						
			$searchstr = " ";

			if ((!empty($searchcriteria['centername'])) and ($searchcriteria['centername'] != "All"))
				$searchstr = $searchstr."AND cc.center_name = '".$searchcriteria['centername']."' ";

			if ((!empty($searchcriteria['session'])) and ($searchcriteria['session'] != "All"))
				$searchstr = $searchstr."AND brh.session = '".$searchcriteria['session']."' ";

			$grade = $searchcriteria['gradename'];

			if ($grade != "Pre-K")
			{
				if ($grade == "K")
					$prevgrade = "Pre-K";
				else
				{
					if ($grade == "1")
						$prevgrade = "K";
					else
						$prevgrade = strval(intval($grade)-1);
				}
		
				$searchstrgrd = "AND brh.grade = '".$prevgrade."' ";
				$searchstrfin = $searchstr.$searchstrgrd;
				
				$searchstr1 = " ";
				if ((!empty($searchcriteria['centername'])) and ($searchcriteria['centername'] != "All"))
					$searchstr1 = $searchstr1."AND cc1.center_name = '".$searchcriteria['centername']."' ";
	
				if ((!empty($searchcriteria['session'])) and ($searchcriteria['session'] != "All"))
					$searchstr1 = $searchstr1."AND brh1.session = '".$searchcriteria['session']."' ";

				$searchstrgrd1 = "AND brh1.grade = '".$grade."' ";
				$searchstrfin1 = $searchstr1.$searchstrgrd1;

				//Get unregistered members
				if (($searchcriteria['status'] == "All") || ($searchcriteria['status'] == "Unregistered"))
                {
    				$tmp = $this->db->query('			
    						SELECT
    							brh.person_id_fk,
    							p.first_name,
    							IFNULL(p.last_name,' . $this->db->escape("") . ') AS last_name,
    							brh.grade,
    							brh.session,
    							cc.center_name,
    							IFNULL(p.city,' . $this->db->escape("") . ') AS city,
    							IFNULL(p.state,' . $this->db->escape("") . ') AS state,
    							IFNULL(tg.teacher_group_id,0) AS teacher_group_id,
    		           			(SELECT p1.phone1 FROM household_xref hxr1 INNER JOIN person p1 ON p1.person_id=hxr1.person_id_fk WHERE p1.enabled=1 AND p1.cmb_member=1 AND hxr1.household_id_fk=hh.household_id AND hxr1.member_type=' . $this->db->escape("Primary") . ' GROUP BY p1.person_id) AS parent_phone,
    							IFNULL(p.email1,' . $this->db->escape("") . ') AS child_email,					
    	           				(SELECT p1.email1 FROM household_xref hxr1 INNER JOIN person p1 ON p1.person_id=hxr1.person_id_fk WHERE p1.enabled=1 AND p1.cmb_member=1 AND hxr1.household_id_fk=hh.household_id AND hxr1.member_type=' . $this->db->escape("Primary") . ' GROUP BY p1.person_id) AS parent_email,
    	          				(SELECT CONCAT_WS(' . $this->db->escape(" ") . ',IFNULL(p1.first_name,' . $this->db->escape("") . '),IFNULL(p1.last_name,' . $this->db->escape("") . ')) FROM household_xref hxr1 INNER JOIN person p1 ON p1.person_id=hxr1.person_id_fk WHERE p1.enabled=1 AND p1.cmb_member=1 AND hxr1.household_id_fk=hh.household_id AND hxr1.member_type=' . $this->db->escape("Primary") . ' GROUP BY p1.person_id) AS parent_name,
    							IFNULL(DATE_FORMAT(p.birth_date,' . $this->db->escape("%m/%d/%y") . '),' . $this->db->escape("") . ') AS birth_date,
    							hh.household_id
    						FROM bv_reg_history brh
    							INNER JOIN person p ON p.person_id = brh.person_id_fk
    							INNER JOIN household_xref hxr ON hxr.person_id_fk=p.person_id
    							INNER JOIN household hh ON hh.household_id=hxr.household_id_fk
    							INNER JOIN cmb_reg_history crh ON crh.household_id_fk=hh.household_id AND crh.year = ' . $this->db->escape($specifiedyear-1) . '
    							INNER JOIN grade g ON g.grade_name = brh.grade
    							INNER JOIN cmb_center cc ON cc.cmb_center_id=brh.cmb_center_id_fk
    							LEFT OUTER JOIN teacher_group tg ON tg.teacher_group_id=brh.teacher_group_id_fk
    						WHERE
    							p.cmb_member = 1
    							AND p.enabled = 1
    							AND brh.enabled = 1
    							AND tg.enabled = 1
    							AND hxr.enabled = 1
    							AND hh.enabled = 1
    							AND brh.year = ' . $this->db->escape($specifiedyear-1) . $searchstrfin . '
    							AND brh.person_id_fk NOT IN
    							(
    								SELECT
    									brh1.person_id_fk
    								FROM bv_reg_history brh1
    									INNER JOIN person p1 ON p1.person_id = brh1.person_id_fk
    									INNER JOIN household_xref hxr1 ON hxr1.person_id_fk=p1.person_id
    									INNER JOIN household hh1 ON hh1.household_id=hxr1.household_id_fk
    									INNER JOIN cmb_reg_history crh1 ON crh1.household_id_fk=hh1.household_id AND crh1.year = ' . $this->db->escape($specifiedyear) . '
    									INNER JOIN grade g1 ON g1.grade_name = brh1.grade
    									INNER JOIN cmb_center cc1 ON cc1.cmb_center_id=brh1.cmb_center_id_fk
    									LEFT OUTER JOIN teacher_group tg1 ON tg1.teacher_group_id=brh1.teacher_group_id_fk
    								WHERE
    									p1.cmb_member = 1
    									AND p1.enabled = 1
    									AND brh1.enabled = 1
    									AND hxr1.enabled = 1
    									AND hh1.enabled = 1
    									AND tg1.enabled = 1
    									AND brh1.year = ' . $this->db->escape($specifiedyear) . $searchstrfin1 . '
    							)
    						GROUP BY p.person_id
    						ORDER BY g.grade_id ASC, brh.session ASC, p.last_name ASC;
    						');
    	
    				if($tmp->num_rows() > 0)
    				{											  
    					foreach ($tmp->result() as $bvRow)
    					{
    						$bvrec = array();
    						
    						$bvrec['firstname'] = $bvRow->first_name;
    						$bvrec['lastname'] = $bvRow->last_name;
    						//$bvrec['gradename'] = $bvRow->grade;
    						$bvrec['gradename'] = $grade;
    						$bvrec['session'] = $bvRow->session;
    						$bvrec['centername'] = $bvRow->center_name;
    						$bvrec['city'] = $bvRow->city;
    						$bvrec['state'] = $bvRow->state;						
    						$bvrec['fully_paid'] = "Unregistered";							
    						//$bvrec['teacher_group_id'] = $bvRow->teacher_group_id;
                            $cmb_center_id = $this->Walk_proxy->getCenterID($searchcriteria['centername']);
                            $bvrec['teacher_group_id'] = $this->Walk_proxy->getTeacherGroupID($cmb_center_id, $specifiedyear, $searchcriteria['session'], $grade);
    						$bvrec['child_email'] = $bvRow->child_email;
    						$bvrec['parent_phone'] = $bvRow->parent_phone;
    						$bvrec['parent_email'] = $bvRow->parent_email;
    						$bvrec['birth_date'] = $bvRow->birth_date;
    						$bvrec['household_id'] = $bvRow->household_id;
    						$bvrec['parent_name'] = $bvRow->parent_name;
    	
    						array_push($bvinfoarr, $bvrec);
    						array_push($arridx,strtolower($bvRow->last_name));
    						
    						unset($bvrec);
    					}
    				}
				}
			}
			else
				$prevgrade = $grade;
				
			$searchstrgrd = "AND brh.grade = '".$grade."' ";
			$searchstrfin = $searchstr.$searchstrgrd;
			
			//Get registered members
            if (($searchcriteria['status'] == "All") || ($searchcriteria['status'] == "Registered"))
            {
				    $tmp = $this->db->query('			
					SELECT
						brh.person_id_fk,
						p.first_name,
						IFNULL(p.last_name,' . $this->db->escape("") . ') AS last_name,
						brh.grade,
						brh.session,
						cc.center_name,
						IFNULL(p.city,' . $this->db->escape("") . ') AS city,
						IFNULL(p.state,' . $this->db->escape("") . ') AS state,
						crh.fully_paid,
						IFNULL(tg.teacher_group_id,0) AS teacher_group_id,
	           			(SELECT p1.phone1 FROM household_xref hxr1 INNER JOIN person p1 ON p1.person_id=hxr1.person_id_fk WHERE p1.enabled=1 AND p1.cmb_member=1 AND hxr1.household_id_fk=hh.household_id AND hxr1.member_type=' . $this->db->escape("Primary") . ' GROUP BY p1.person_id) AS parent_phone,
						IFNULL(p.email1,' . $this->db->escape("") . ') AS child_email,					
           				(SELECT p1.email1 FROM household_xref hxr1 INNER JOIN person p1 ON p1.person_id=hxr1.person_id_fk WHERE p1.enabled=1 AND p1.cmb_member=1 AND hxr1.household_id_fk=hh.household_id AND hxr1.member_type=' . $this->db->escape("Primary") . ' GROUP BY p1.person_id) AS parent_email,
          				(SELECT CONCAT_WS(' . $this->db->escape(" ") . ',IFNULL(p1.first_name,' . $this->db->escape("") . '),IFNULL(p1.last_name,' . $this->db->escape("") . ')) FROM household_xref hxr1 INNER JOIN person p1 ON p1.person_id=hxr1.person_id_fk WHERE p1.enabled=1 AND p1.cmb_member=1 AND hxr1.household_id_fk=hh.household_id AND hxr1.member_type=' . $this->db->escape("Primary") . ' GROUP BY p1.person_id) AS parent_name,
						IFNULL(DATE_FORMAT(p.birth_date,' . $this->db->escape("%m/%d/%y") . '),' . $this->db->escape("") . ') AS birth_date,
						hh.household_id
					FROM bv_reg_history brh
						INNER JOIN person p ON p.person_id = brh.person_id_fk
						INNER JOIN household_xref hxr ON hxr.person_id_fk=p.person_id
						INNER JOIN household hh ON hh.household_id=hxr.household_id_fk
						INNER JOIN cmb_reg_history crh ON crh.household_id_fk=hh.household_id AND crh.year = ' . $this->db->escape($specifiedyear) . '
						INNER JOIN grade g ON g.grade_name = brh.grade
						INNER JOIN cmb_center cc ON cc.cmb_center_id=brh.cmb_center_id_fk
						LEFT OUTER JOIN teacher_group tg ON tg.teacher_group_id=brh.teacher_group_id_fk
					WHERE
						p.cmb_member = 1
						AND p.enabled = 1
						AND brh.enabled = 1
						AND tg.enabled = 1
						AND hxr.enabled = 1
						AND hh.enabled = 1
						AND brh.year = ' . $this->db->escape($specifiedyear) . $searchstrfin . '
					GROUP BY p.person_id
					ORDER BY g.grade_id ASC, brh.session ASC, p.last_name ASC;
					');

    			if($tmp->num_rows() > 0)
    			{											  
    				foreach ($tmp->result() as $bvRow)
    				{
    					$bvrec = array();
    					
    					$bvrec['firstname'] = $bvRow->first_name;
    					$bvrec['lastname'] = $bvRow->last_name;
    					$bvrec['gradename'] = $bvRow->grade;
    					$bvrec['session'] = $bvRow->session;
    					$bvrec['centername'] = $bvRow->center_name;
    					$bvrec['city'] = $bvRow->city;
    					$bvrec['state'] = $bvRow->state;
    					
    					if ($bvRow->fully_paid == 1)
    						$bvrec['fully_paid'] = "Registered-Paid";
    					else
    						$bvrec['fully_paid'] = "Registered-Unpaid";
    						
    					//$bvrec['teacher_group_id'] = $bvRow->teacher_group_id;
                        $cmb_center_id = $this->Walk_proxy->getCenterID($searchcriteria['centername']);
                        $bvrec['teacher_group_id'] = $this->Walk_proxy->getTeacherGroupID($cmb_center_id, $specifiedyear, $searchcriteria['session'], $grade);
    					$bvrec['child_email'] = $bvRow->child_email;
    					$bvrec['parent_phone'] = $bvRow->parent_phone;
    					$bvrec['parent_email'] = $bvRow->parent_email;
    					$bvrec['birth_date'] = $bvRow->birth_date;
    					$bvrec['household_id'] = $bvRow->household_id;
    					$bvrec['parent_name'] = $bvRow->parent_name;
    
    					array_push($bvinfoarr, $bvrec);
    					array_push($arridx,strtolower($bvRow->last_name));
    				}
    			}
			}
	
			if (count($arridx) > 0)
			{
				//Sort by last_name
				asort($arridx);
				
				foreach ($arridx as $key => $val)
				{
					$idx = intval($key);
					$tmprec = $bvinfoarr[$idx];
					array_push($bvinfoarrsrt, $tmprec);
					//echo $tmprec[0].",".$tmprec[1].",".$tmprec[2].",".$tmprec[3].",".$tmprec[4]."</br>";
				}		
				
				unset($bvinfoarr);
				unset($arridx);
			}

			return 	$bvinfoarrsrt;		
		}		
		
		//Get Balavihar class assignment information for a specified year and teacher group
		public function getBalaviharClassAssignmentDataTG( $specifiedyear, $tgid, $status )
		{
			$this->load->model('proxies/Walk_proxy');

			$bvinfoarr = array();
			$arridx = array();
			$bvinfoarrsrt = array();
			
			$grade = $this->Walk_proxy->getGradeFromTeacherGroups($tgid);
			$session = $this->Walk_proxy->getSessionFromTeacherGroups($tgid);
			$center = $this->Walk_proxy->getCenterFromTeacherGroups($tgid);
						
			if ($grade != "Pre-K")
			{
				if ($grade == "K")
					$prevgrade = "Pre-K";
				else
				{
					if ($grade == "1")
						$prevgrade = "K";
					else
						$prevgrade = strval(intval($grade)-1);
				}
		
                //Get all unregistered members from previous year
                if (($status == "All") || ($status == "Unregistered"))
                {
    				$tmp = $this->db->query('			
    						SELECT
    							brh.person_id_fk,
    							p.first_name,
    							IFNULL(p.last_name,' . $this->db->escape("") . ') AS last_name,
    							brh.grade,
    							brh.session,
    							cc.center_name,
    							IFNULL(p.city,' . $this->db->escape("") . ') AS city,
    							IFNULL(p.state,' . $this->db->escape("") . ') AS state,
    		           			(SELECT p1.phone1 FROM household_xref hxr1 INNER JOIN person p1 ON p1.person_id=hxr1.person_id_fk WHERE p1.enabled=1 AND p1.cmb_member=1 AND hxr1.household_id_fk=hh.household_id AND hxr1.member_type=' . $this->db->escape("Primary") . ' GROUP BY p1.person_id) AS parent_phone,
    							IFNULL(p.email1,' . $this->db->escape("") . ') AS child_email,					
    	           				(SELECT p1.email1 FROM household_xref hxr1 INNER JOIN person p1 ON p1.person_id=hxr1.person_id_fk WHERE p1.enabled=1 AND p1.cmb_member=1 AND hxr1.household_id_fk=hh.household_id AND hxr1.member_type=' . $this->db->escape("Primary") . ' GROUP BY p1.person_id) AS parent_email,
    	          				(SELECT CONCAT_WS(' . $this->db->escape(" ") . ',IFNULL(p1.first_name,' . $this->db->escape("") . '),IFNULL(p1.last_name,' . $this->db->escape("") . ')) FROM household_xref hxr1 INNER JOIN person p1 ON p1.person_id=hxr1.person_id_fk WHERE p1.enabled=1 AND p1.cmb_member=1 AND hxr1.household_id_fk=hh.household_id AND hxr1.member_type=' . $this->db->escape("Primary") . ' GROUP BY p1.person_id) AS parent_name,
    							IFNULL(DATE_FORMAT(p.birth_date,' . $this->db->escape("%m/%d/%y") . '),' . $this->db->escape("") . ') AS birth_date,
    							hh.household_id
    						FROM bv_reg_history brh
    							INNER JOIN person p ON p.person_id = brh.person_id_fk
    							INNER JOIN household_xref hxr ON hxr.person_id_fk=p.person_id
    							INNER JOIN household hh ON hh.household_id=hxr.household_id_fk
    							INNER JOIN cmb_reg_history crh ON crh.household_id_fk=hh.household_id AND crh.year = ' . $this->db->escape($specifiedyear-1) . '
    							INNER JOIN grade g ON g.grade_name = brh.grade
    							INNER JOIN cmb_center cc ON cc.cmb_center_id=brh.cmb_center_id_fk
    							LEFT OUTER JOIN teacher_group tg ON tg.teacher_group_id=brh.teacher_group_id_fk
    						WHERE
    							p.cmb_member = 1
    							AND p.enabled = 1
    							AND brh.enabled = 1
    							AND hxr.enabled = 1
    							AND hh.enabled = 1
    							AND tg.enabled = 1
    							AND brh.grade = ' . $this->db->escape($prevgrade) . '
    							AND brh.session = ' . $this->db->escape($session) . '
    							AND cc.center_name = ' . $this->db->escape($center) . '							
    							AND brh.year = ' . $this->db->escape($specifiedyear-1) . '
    							AND brh.person_id_fk NOT IN
    							(
    								SELECT
    									brh1.person_id_fk
    								FROM bv_reg_history brh1
    									INNER JOIN person p1 ON p1.person_id = brh1.person_id_fk
    									INNER JOIN household_xref hxr1 ON hxr1.person_id_fk=p1.person_id
    									INNER JOIN household hh1 ON hh1.household_id=hxr1.household_id_fk
    									INNER JOIN cmb_reg_history crh1 ON crh1.household_id_fk=hh1.household_id AND crh1.year = ' . $this->db->escape($specifiedyear) . '
    									INNER JOIN grade g1 ON g1.grade_name = brh1.grade
    									INNER JOIN cmb_center cc1 ON cc1.cmb_center_id=brh1.cmb_center_id_fk
    									LEFT OUTER JOIN teacher_group tg1 ON tg1.teacher_group_id=brh1.teacher_group_id_fk
    								WHERE
    									p1.cmb_member = 1
    									AND p1.enabled = 1
    									AND brh1.enabled = 1
    									AND hxr1.enabled = 1
    									AND hh1.enabled = 1
    									AND tg1.enabled = 1
    									AND tg1.teacher_group_id = ' . $this->db->escape($tgid) . '
    									AND brh1.year = ' . $this->db->escape($specifiedyear) . '
    							)
    						GROUP BY p.person_id
    						ORDER BY g.grade_id ASC, brh.session ASC, p.last_name ASC;
    						');
                    
                    if($tmp->num_rows() > 0)
    				{											  
    					foreach ($tmp->result() as $bvRow)
    					{
    						$bvrec = array();
    						
    						$bvrec['firstname'] = $bvRow->first_name;
    						$bvrec['lastname'] = $bvRow->last_name;
    						//$bvrec['gradename'] = $bvRow->grade;
    						$bvrec['gradename'] = $grade;
    						$bvrec['session'] = $bvRow->session;
    						$bvrec['centername'] = $bvRow->center_name;
    						$bvrec['city'] = $bvRow->city;
    						$bvrec['state'] = $bvRow->state;						
    						$bvrec['fully_paid'] = "Unregistered";							
    						$bvrec['teacher_group_id'] = $tgid;
    						$bvrec['child_email'] = $bvRow->child_email;
    						$bvrec['parent_phone'] = $bvRow->parent_phone;
    						$bvrec['parent_email'] = $bvRow->parent_email;
    						$bvrec['birth_date'] = $bvRow->birth_date;
    						$bvrec['household_id'] = $bvRow->household_id;
    						$bvrec['parent_name'] = $bvRow->parent_name;
    	
    						array_push($bvinfoarr, $bvrec);
    						array_push($arridx,strtolower($bvRow->last_name));
    						
    						unset($bvrec);
    					}
    				}
				}
			}
			else
				$prevgrade = $grade;
				
			//Get all registrants for current year
            if (($status == "All") || ($status == "Registered"))
            {
    			$tmp = $this->db->query('			
    					SELECT
    						brh.person_id_fk,
    						p.first_name,
    						IFNULL(p.last_name,' . $this->db->escape("") . ') AS last_name,
    						brh.grade,
    						brh.session,
    						cc.center_name,
    						IFNULL(p.city,' . $this->db->escape("") . ') AS city,
    						IFNULL(p.state,' . $this->db->escape("") . ') AS state,
    						crh.fully_paid,
    						IFNULL(tg.teacher_group_id,0) AS teacher_group_id,
    	           			(SELECT p1.phone1 FROM household_xref hxr1 INNER JOIN person p1 ON p1.person_id=hxr1.person_id_fk WHERE p1.enabled=1 AND p1.cmb_member=1 AND hxr1.household_id_fk=hh.household_id AND hxr1.member_type=' . $this->db->escape("Primary") . ' GROUP BY p1.person_id) AS parent_phone,
    						IFNULL(p.email1,' . $this->db->escape("") . ') AS child_email,					
               				(SELECT p1.email1 FROM household_xref hxr1 INNER JOIN person p1 ON p1.person_id=hxr1.person_id_fk WHERE p1.enabled=1 AND p1.cmb_member=1 AND hxr1.household_id_fk=hh.household_id AND hxr1.member_type=' . $this->db->escape("Primary") . ' GROUP BY p1.person_id) AS parent_email,
              				(SELECT CONCAT_WS(' . $this->db->escape(" ") . ',IFNULL(p1.first_name,' . $this->db->escape("") . '),IFNULL(p1.last_name,' . $this->db->escape("") . ')) FROM household_xref hxr1 INNER JOIN person p1 ON p1.person_id=hxr1.person_id_fk WHERE p1.enabled=1 AND p1.cmb_member=1 AND hxr1.household_id_fk=hh.household_id AND hxr1.member_type=' . $this->db->escape("Primary") . ' GROUP BY p1.person_id) AS parent_name,
    						IFNULL(DATE_FORMAT(p.birth_date,' . $this->db->escape("%m/%d/%y") . '),' . $this->db->escape("") . ') AS birth_date,
    						hh.household_id
    					FROM bv_reg_history brh
    						INNER JOIN person p ON p.person_id = brh.person_id_fk
    						INNER JOIN household_xref hxr ON hxr.person_id_fk=p.person_id
    						INNER JOIN household hh ON hh.household_id=hxr.household_id_fk
    						INNER JOIN cmb_reg_history crh ON crh.household_id_fk=hh.household_id AND crh.year = ' . $this->db->escape($specifiedyear) . '
    						INNER JOIN grade g ON g.grade_name = brh.grade
    						INNER JOIN cmb_center cc ON cc.cmb_center_id=brh.cmb_center_id_fk
    						LEFT OUTER JOIN teacher_group tg ON tg.teacher_group_id=brh.teacher_group_id_fk
    					WHERE
    						p.cmb_member = 1
    						AND p.enabled = 1
    						AND brh.enabled = 1
    						AND tg.enabled = 1
    						AND hxr.enabled = 1
    						AND hh.enabled = 1
    						AND tg.teacher_group_id = ' . $this->db->escape($tgid) . '
    						AND brh.year = ' . $this->db->escape($specifiedyear) . '
    					GROUP BY p.person_id
    					ORDER BY g.grade_id ASC, brh.session ASC, p.last_name ASC;
    					');
    
    			if($tmp->num_rows() > 0)
    			{											  
    				foreach ($tmp->result() as $bvRow)
    				{
    					$bvrec = array();
    					
    					$bvrec['firstname'] = $bvRow->first_name;
    					$bvrec['lastname'] = $bvRow->last_name;
    					$bvrec['gradename'] = $bvRow->grade;
    					$bvrec['session'] = $bvRow->session;
    					$bvrec['centername'] = $bvRow->center_name;
    					$bvrec['city'] = $bvRow->city;
    					$bvrec['state'] = $bvRow->state;
    					
    					if ($bvRow->fully_paid == 1)
    						$bvrec['fully_paid'] = "Registered-Paid";
    					else
    						$bvrec['fully_paid'] = "Registered-Unpaid";
    						
    					$bvrec['teacher_group_id'] = $bvRow->teacher_group_id;
    					$bvrec['child_email'] = $bvRow->child_email;
    					$bvrec['parent_phone'] = $bvRow->parent_phone;
    					$bvrec['parent_email'] = $bvRow->parent_email;
    					$bvrec['birth_date'] = $bvRow->birth_date;
    					$bvrec['household_id'] = $bvRow->household_id;
    					$bvrec['parent_name'] = $bvRow->parent_name;
    
    					array_push($bvinfoarr, $bvrec);
    					array_push($arridx,strtolower($bvRow->last_name));
    				}
    			}
			}
	
			if (count($arridx) > 0)
			{
				//Sort by last_name
				asort($arridx);
				
				foreach ($arridx as $key => $val)
				{
					$idx = intval($key);
					$tmprec = $bvinfoarr[$idx];
					array_push($bvinfoarrsrt, $tmprec);
					//echo $tmprec[0].",".$tmprec[1].",".$tmprec[2].",".$tmprec[3].",".$tmprec[4]."</br>";
				}		
				
				unset($bvinfoarr);
				unset($arridx);
			}

			return 	$bvinfoarrsrt;		
		}		
/*
		//Get Balavihar class assignment information for a specified year
		public function getBalaviharClassAssignmentData( $specifiedyear, $searchcriteria )
		{
			$bvinfoarr = array();
						
			$searchstr = " ";

			if ((!empty($searchcriteria['centername'])) and ($searchcriteria['centername'] != "All"))
				$searchstr = $searchstr."AND cc.center_name = '".$searchcriteria['centername']."' ";

			if ((!empty($searchcriteria['session'])) and ($searchcriteria['session'] != "All"))
				$searchstr = $searchstr."AND brh.session = '".$searchcriteria['session']."' ";

			if ((!empty($searchcriteria['gradename'])) and ($searchcriteria['gradename'] != "All"))
				$searchstr = $searchstr."AND brh.grade = '".$searchcriteria['gradename']."' ";

			$tmp = $this->db->query('			
					SELECT
						p.first_name,
						IFNULL(p.last_name,' . $this->db->escape("") . ') AS last_name,
						brh.grade,
						brh.session,
						cc.center_name,
						IFNULL(p.city,' . $this->db->escape("") . ') AS city,
						IFNULL(p.state,' . $this->db->escape("") . ') AS state,
						crh.fully_paid,
						IFNULL(tg.teacher_group_id,0) AS teacher_group_id,
	           			(SELECT p1.phone1 FROM household_xref hxr1 INNER JOIN person p1 ON p1.person_id=hxr1.person_id_fk WHERE p1.enabled=1 AND p1.cmb_member=1 AND hxr1.household_id_fk=hh.household_id AND hxr1.member_type=' . $this->db->escape("Primary") . ' GROUP BY p1.person_id) AS parent_phone,
						IFNULL(p.email1,' . $this->db->escape("") . ') AS child_email,					
           				(SELECT p1.email1 FROM household_xref hxr1 INNER JOIN person p1 ON p1.person_id=hxr1.person_id_fk WHERE p1.enabled=1 AND p1.cmb_member=1 AND hxr1.household_id_fk=hh.household_id AND hxr1.member_type=' . $this->db->escape("Primary") . ' GROUP BY p1.person_id) AS parent_email,
          				(SELECT CONCAT_WS(' . $this->db->escape(" ") . ',IFNULL(p1.first_name,' . $this->db->escape("") . '),IFNULL(p1.last_name,' . $this->db->escape("") . ')) FROM household_xref hxr1 INNER JOIN person p1 ON p1.person_id=hxr1.person_id_fk WHERE p1.enabled=1 AND p1.cmb_member=1 AND hxr1.household_id_fk=hh.household_id AND hxr1.member_type=' . $this->db->escape("Primary") . ' GROUP BY p1.person_id) AS parent_name,
						IFNULL(DATE_FORMAT(p.birth_date,' . $this->db->escape("%m/%d/%y") . '),' . $this->db->escape("") . ') AS birth_date,
						hh.household_id
					FROM bv_reg_history brh
						INNER JOIN person p ON p.person_id = brh.person_id_fk
						INNER JOIN household_xref hxr ON hxr.person_id_fk=p.person_id
						INNER JOIN household hh ON hh.household_id=hxr.household_id_fk
						INNER JOIN cmb_reg_history crh ON crh.household_id_fk=hh.household_id AND crh.year = ' . $this->db->escape($specifiedyear) . '
						INNER JOIN grade g ON g.grade_name = brh.grade
						INNER JOIN cmb_center cc ON cc.cmb_center_id=brh.cmb_center_id_fk
						LEFT OUTER JOIN teacher_group tg ON tg.teacher_group_id=brh.teacher_group_id_fk
					WHERE
						p.cmb_member = 1
						AND p.enabled = 1
						AND brh.enabled = 1
						AND tg.enabled = 1
						AND hxr.enabled = 1
						AND hh.enabled = 1
						AND brh.year = ' . $this->db->escape($specifiedyear) . $searchstr .
					'GROUP BY p.person_id
					ORDER BY g.grade_id ASC, brh.session ASC, p.last_name ASC;
					');

			if($tmp->num_rows() > 0)
			{											  
				foreach ($tmp->result() as $bvRow)
				{
					$bvrec = array();
					
					$bvrec['firstname'] = $bvRow->first_name;
					$bvrec['lastname'] = $bvRow->last_name;
					$bvrec['gradename'] = $bvRow->grade;
					$bvrec['session'] = $bvRow->session;
					$bvrec['centername'] = $bvRow->center_name;
					$bvrec['city'] = $bvRow->city;
					$bvrec['state'] = $bvRow->state;
					
					if ($bvRow->fully_paid == 1)
						$bvrec['fully_paid'] = "Paid";
					else
						$bvrec['fully_paid'] = "Unpaid";
						
					$bvrec['teacher_group_id'] = $bvRow->teacher_group_id;
					$bvrec['child_email'] = $bvRow->child_email;
					$bvrec['parent_phone'] = $bvRow->parent_phone;
					$bvrec['parent_email'] = $bvRow->parent_email;
					$bvrec['birth_date'] = $bvRow->birth_date;
					$bvrec['household_id'] = $bvRow->household_id;
					$bvrec['parent_name'] = $bvRow->parent_name;

					array_push($bvinfoarr, $bvrec);
				}
			}
	
			return 	$bvinfoarr;		
		}		
*/
		//Get Balavihar class roster for a specified year and teacher groups
		public function getClassRosterData( $specifiedyear, $teachergroups, $status )
		{
			$tginfoarr = array();
						
			foreach($teachergroups as $tgid)
			{
				$bvinfoarr = $this->getBalaviharClassAssignmentDataTG($specifiedyear, $tgid, $status);
				array_push($tginfoarr, $bvinfoarr);
			}
	
			return 	$tginfoarr;		
		}		

		public function getTeachersFromGroup( $teachergroupId )
		{
			$teacherarr = array();
			
			if ($teachergroupId <= 0)
				return $teacherarr;
			
			$tmp = $this->db->query('
										SELECT
											p.first_name,
											p.last_name
										FROM teacher_group_xref tgx
											INNER JOIN	person p ON p.person_id=tgx.person_id_fk
											INNER JOIN teacher_group tg ON tg.teacher_group_id=tgx.teacher_group_id_fk
										WHERE
											tgx.enabled = 1
											AND tg.enabled = 1
											AND tgx.teacher_group_id_fk = ' . $this->db->escape($teachergroupId) . '
											AND p.cmb_member = 1
											AND p.enabled = 1
										ORDER BY tgx.primary DESC, p.last_name ASC;	
									');
			
			if($tmp->num_rows() > 0)
			{
				foreach ($tmp->result() as $tgRow)
				{			
					array_push($teacherarr, $tgRow->first_name.' '.$tgRow->last_name);
				}
			}
			
			return $teacherarr;
		}
		
		//Get Balavihar data for a specified year
		public function getBalaviharData( $specifiedyear, $searchcriteria )
		{
			$bvinfoarr = array();
						
			$searchstr = " ";
			if (!empty($searchcriteria['memberlastname']))
				$searchstr = " AND p.last_name LIKE '".$searchcriteria['memberlastname']."%' ";
			
			if (!empty($searchcriteria['memberfirstname']))
				$searchstr = $searchstr."AND p.first_name LIKE '".$searchcriteria['memberfirstname']."%' ";

			if (!empty($searchcriteria['membercity']))
				$searchstr = $searchstr."AND p.city LIKE '".$searchcriteria['membercity']."%' ";

			if ((!empty($searchcriteria['memberstate'])) and ($searchcriteria['memberstate'] != "All"))
				$searchstr = $searchstr."AND p.state = '".$searchcriteria['memberstate']."' ";

			if ((!empty($searchcriteria['centername'])) and ($searchcriteria['centername'] != "All"))
				$searchstr = $searchstr."AND cc.center_name = '".$searchcriteria['centername']."' ";

			if ((!empty($searchcriteria['session'])) and ($searchcriteria['session'] != "All"))
				$searchstr = $searchstr."AND brh.session = '".$searchcriteria['session']."' ";

			if ((!empty($searchcriteria['gradename'])) and ($searchcriteria['gradename'] != "All"))
				$searchstr = $searchstr."AND brh.grade = '".$searchcriteria['gradename']."' ";

			$tmp = $this->db->query('			
					SELECT
						p.first_name,
						IFNULL(p.last_name,' . $this->db->escape("") . ') AS last_name,
						brh.grade,
						brh.session,
						cc.center_name,
						IFNULL(p.city,' . $this->db->escape("") . ') AS city,
						IFNULL(p.state,' . $this->db->escape("") . ') AS state,
						IFNULL(DATE_FORMAT(p.birth_date,' . $this->db->escape("%d-%M-%Y") . '),' . $this->db->escape("") . ') AS birth_date						
					FROM bv_reg_history brh
						INNER JOIN person p ON p.person_id = brh.person_id_fk
						INNER JOIN grade g ON g.grade_name = brh.grade
						INNER JOIN cmb_center cc ON cc.cmb_center_id=brh.cmb_center_id_fk
					WHERE
						p.cmb_member = 1
						AND p.enabled = 1
						AND brh.enabled = 1
						AND brh.year = ' . $this->db->escape($specifiedyear) . $searchstr .
					'ORDER BY g.grade_id ASC, brh.session ASC, p.last_name ASC;
					');

			if($tmp->num_rows() > 0)
			{											  
				foreach ($tmp->result() as $bvRow)
				{
					$bvrec = array();
					
					$bvrec['firstname'] = $bvRow->first_name;
					$bvrec['lastname'] = $bvRow->last_name;
					$bvrec['gradename'] = $bvRow->grade;
					$bvrec['session'] = $bvRow->session;
					$bvrec['centername'] = $bvRow->center_name;
					$bvrec['city'] = $bvRow->city;
					$bvrec['state'] = $bvRow->state;

					array_push($bvinfoarr, $bvrec);
				}
			}
	
			return 	$bvinfoarr;		
		}		

		//Get Language Admin data for a specified year
		public function getLanguageAdminData( $specifiedyear, $searchcriteria )
		{
			$langinfoarr = array();
						
			$searchstr = " ";
			if (!empty($searchcriteria['memberlastname']))
				$searchstr = " AND p.last_name LIKE '".$searchcriteria['memberlastname']."%' ";
			
			if (!empty($searchcriteria['memberfirstname']))
				$searchstr = $searchstr."AND p.first_name LIKE '".$searchcriteria['memberfirstname']."%' ";

			if (!empty($searchcriteria['membercity']))
				$searchstr = $searchstr."AND p.city LIKE '".$searchcriteria['membercity']."%' ";

			if ((!empty($searchcriteria['memberstate'])) and ($searchcriteria['memberstate'] != "All"))
				$searchstr = $searchstr."AND p.state = '".$searchcriteria['memberstate']."' ";

			if ((!empty($searchcriteria['centername'])) and ($searchcriteria['centername'] != "All"))
				$searchstr = $searchstr."AND cc.center_name = '".$searchcriteria['centername']."' ";

			if ((!empty($searchcriteria['languagename'])) and ($searchcriteria['languagename'] != "All"))
				$searchstr = $searchstr."AND l.language_name = '".$searchcriteria['languagename']."' ";

			$tmp = $this->db->query('			
					SELECT
						p.first_name,
						IFNULL(p.last_name,' . $this->db->escape("") . ') AS last_name,
						l.language_name,
						lrh.level,
						cc.center_name,
						IFNULL(p.city,' . $this->db->escape("") . ') AS city,
						IFNULL(p.state,' . $this->db->escape("") . ') AS state,
						crh.fully_paid,						
						IFNULL(p.email1,' . $this->db->escape("") . ') AS child_email,					
           				(SELECT p1.phone1 FROM household_xref hxr1 INNER JOIN person p1 ON p1.person_id=hxr1.person_id_fk WHERE p1.enabled=1 AND p1.cmb_member=1 AND hxr1.household_id_fk=hh.household_id AND hxr1.member_type=' . $this->db->escape("Primary") . ' GROUP BY p1.person_id) AS parent_phone,
           				(SELECT p1.email1 FROM household_xref hxr1 INNER JOIN person p1 ON p1.person_id=hxr1.person_id_fk WHERE p1.enabled=1 AND p1.cmb_member=1 AND hxr1.household_id_fk=hh.household_id AND hxr1.member_type=' . $this->db->escape("Primary") . ' GROUP BY p1.person_id) AS parent_email,
      					(SELECT CONCAT_WS(' . $this->db->escape(" ") . ',IFNULL(p1.first_name,' . $this->db->escape("") . '),IFNULL(p1.last_name,' . $this->db->escape("") . ')) FROM household_xref hxr1 INNER JOIN person p1 ON p1.person_id=hxr1.person_id_fk WHERE p1.enabled=1 AND p1.cmb_member=1 AND hxr1.household_id_fk=hh.household_id AND hxr1.member_type=' . $this->db->escape("Primary") . ' GROUP BY p1.person_id) AS parent_name,
						IFNULL(DATE_FORMAT(p.birth_date,' . $this->db->escape("%m/%d/%y") . '),' . $this->db->escape("") . ') AS birth_date,
						hh.household_id
					FROM lang_reg_history lrh
						INNER JOIN person p ON p.person_id = lrh.person_id_fk
           				INNER JOIN household_xref hxr ON hxr.person_id_fk=lrh.person_id_fk
            			INNER JOIN household hh ON hh.household_id=hxr.household_id_fk
						INNER JOIN cmb_reg_history crh ON crh.household_id_fk=hh.household_id
						INNER JOIN cmb_center cc ON cc.cmb_center_id=lrh.cmb_center_id_fk
						INNER JOIN language l ON l.language_id=lrh.language_id_fk
					WHERE
						p.cmb_member = 1
						AND p.enabled = 1
						AND hxr.enabled = 1
						AND hh.enabled = 1
						AND lrh.enabled = 1
						AND crh.year = ' . $this->db->escape($specifiedyear) .'
						AND lrh.year = ' . $this->db->escape($specifiedyear) . $searchstr .
					'ORDER BY cc.center_name,l.language_name ASC,lrh.level,p.last_name ASC;
					');

			if($tmp->num_rows() > 0)
			{											  
				foreach ($tmp->result() as $langRow)
				{
					$langrec = array();
					
					$langrec['firstname'] = $langRow->first_name;
					$langrec['lastname'] = $langRow->last_name;
					$langrec['languagename'] = $langRow->language_name;
					$langrec['langlevel'] = $langRow->level;
					$langrec['centername'] = $langRow->center_name;
					$langrec['city'] = $langRow->city;
					$langrec['state'] = $langRow->state;
					$langrec['child_email'] = $langRow->child_email;
					$langrec['parent_phone'] = $langRow->parent_phone;
					$langrec['parent_email'] = $langRow->parent_email;
					$langrec['birth_date'] = $langRow->birth_date;
					$langrec['household_id'] = $langRow->household_id;
					$langrec['parent_name'] = $langRow->parent_name;
					if ($langRow->fully_paid == 1)
						$langrec['fully_paid'] = "Registered-Paid";
					else
						$langrec['fully_paid'] = "Registered-Unpaid";

					array_push($langinfoarr, $langrec);
				}
			}
	
			return 	$langinfoarr;		
		}		

		//Get Swamivisits Admin data for a specified year
		public function getSwamivisitsAdminData( $specifiedyear, $searchcriteria )
		{
			$svinfoarr = array();
						
			$searchstr = " ";
			if (!empty($searchcriteria['memberlastname']))
				$searchstr = " AND svrh.last_name LIKE '".$searchcriteria['memberlastname']."%' ";
			
			if (!empty($searchcriteria['memberfirstname']))
				$searchstr = $searchstr."AND svrh.first_name LIKE '".$searchcriteria['memberfirstname']."%' ";

			if ($searchcriteria['regstatus'] != "All")
			{
				if ($searchcriteria['regstatus'] == "Paid")
					$searchstr = $searchstr."AND svrh.payment_status = 1 ";
				else
					$searchstr = $searchstr."AND svrh.payment_status <> 1 ";
			}

			$tmp = $this->db->query('			
					SELECT
						svrh.first_name,
						svrh.last_name,
						svrh.email,
						svrh.numreg,
						svrh.payment_status,
						sve.description						
					FROM sv_reg_history svrh
						INNER JOIN sv_event sve ON sve.sv_event_id = svrh.sv_event_id_fk
					WHERE
						svrh.enabled = 1
						AND svrh.year = ' . $this->db->escape($specifiedyear) . $searchstr .
					'ORDER BY svrh.last_name ASC;
					');

			if($tmp->num_rows() > 0)
			{											  
				foreach ($tmp->result() as $svRow)
				{
					$svrec = array();
					
					$svrec['firstname'] = $svRow->first_name;
					$svrec['lastname'] = $svRow->last_name;
					$svrec['email'] = $svRow->email;
					$svrec['numreg'] = $svRow->numreg;
					
					if ($svRow->payment_status == 1)
						$svrec['paystatus'] = 'Paid';
					else
						$svrec['paystatus'] = 'Unpaid';

					$svrec['event'] = $svRow->description;

					array_push($svinfoarr, $svrec);
				}
			}
	
			return 	$svinfoarr;		
		}		
		
		//Get Banquet Admin data for a specified year
		public function getBanquetAdminData( $specifiedyear, $searchcriteria )
		{
			$bqinfoarr = array();
						
			$searchstr = " ";
			if (!empty($searchcriteria['memberlastname']))
				$searchstr = " AND bqrh.last_name LIKE '".$searchcriteria['memberlastname']."%' ";
			
			if (!empty($searchcriteria['memberfirstname']))
				$searchstr = $searchstr."AND bqrh.first_name LIKE '".$searchcriteria['memberfirstname']."%' ";

			if ($searchcriteria['regstatus'] != "All")
			{
				if ($searchcriteria['regstatus'] == "Paid")
					$searchstr = $searchstr."AND bqrh.payment_status = 1 ";
				else
					$searchstr = $searchstr."AND bqrh.payment_status <> 1 ";
			}

			$tmp = $this->db->query('			
					SELECT
						bqrh.first_name,
						bqrh.last_name,
						bqrh.email,
						bqrh.phone,
						bqrh.address,
						bqrh.city,
						bqrh.state,
						bqrh.zip,
						bqrh.numadultreg,
						bqrh.numchildreg,
						bqrh.payment_status,
						bqrh.amount_paid,
						bqrh.donation_amount,
						bqrh.is_teacher,
						bqrh.teacher_discount,
						bqrh.reg_fee,
						bqrh.date_created,
						bqe.description
					FROM bq_reg_history bqrh
						INNER JOIN bq_event bqe ON bqe.bq_event_id = bqrh.bq_event_id_fk
					WHERE
						bqrh.enabled = 1
						AND bqrh.year = ' . $this->db->escape($specifiedyear) . $searchstr .
					'ORDER BY bqrh.last_name ASC;
					');

			if($tmp->num_rows() > 0)
			{											  
				foreach ($tmp->result() as $bqRow)
				{
					$bqrec = array();
					
					$bqrec['firstname'] = $bqRow->first_name;
					$bqrec['lastname'] = $bqRow->last_name;
					$bqrec['email'] = $bqRow->email;
					$bqrec['phone'] = $bqRow->phone;
					$bqrec['address'] = $bqRow->address;
					$bqrec['city'] = $bqRow->city;
					$bqrec['state'] = $bqRow->state;
					$bqrec['zip'] = $bqRow->zip;
					$bqrec['numadultreg'] = $bqRow->numadultreg;
					$bqrec['numchildreg'] = $bqRow->numchildreg;
					
					if ($bqRow->payment_status == 1)
						$bqrec['paystatus'] = 'Paid';
					else
						$bqrec['paystatus'] = 'Unpaid';

					$bqrec['desc'] = $bqRow->description;
					$bqrec['amount_paid'] = $bqRow->amount_paid;
					$bqrec['donation_amount'] = $bqRow->donation_amount;
                    $bqrec['teacher_discount'] = $bqRow->teacher_discount;
                    $bqrec['reg_fee'] = $bqRow->reg_fee;
                    $bqrec['date_created'] = $bqRow->date_created;

					array_push($bqinfoarr, $bqrec);
				}
			}
	
			return 	$bqinfoarr;		
		}			

		//Get Balavihar attendance for specified class across all weeks
		public function getBalaviharClassAttendanceData( $curyear, $searchcriteria )
		{
			$tmp = $this->db->query('
								SELECT bw.seq
								FROM bv_week bw
								WHERE
									bw.year = ' . $this->db->escape($curyear) . '
								ORDER BY bw.seq ASC
							');
							 
			$numweeks = $tmp->num_rows();			
			$weekseqarr = array();
				
			if( $numweeks > 0)
			{
				foreach ($tmp->result() as $wkRow)
				{				
					array_push($weekseqarr, $wkRow->seq);
				}
			}
			else
				return $weekseqarr;

			$bvattendanceclass = array();
			$grade = $searchcriteria['gradename'];
						
			foreach ($weekseqarr as $wkSeq)
			{
				$arridx = array();
				$bvattendanceweek = array();
				
				//Get attendance data from previous year				
				if ($grade != "Pre-K")
				{
					if ($grade == "K")
						$prevgrade = "Pre-K";
					else
					{
						if ($grade == "1")
							$prevgrade = "K";
						else
							$prevgrade = strval(intval($grade)-1);
					}
/*					
					$tmp = $this->db->query('
										SELECT
										bvw.seq,
										DATE_FORMAT(bvw.bow_date,' . $this->db->escape("%d-%b-%Y") . ') AS bowdate,
										p.first_name,
										p.last_name,
										bvax.status,
										IFNULL(tg.teacher_group_id,0) AS teacher_group_id
										FROM bv_attend_xref bvax
										INNER JOIN bv_reg_history brh ON brh.person_id_fk=bvax.person_id_fk
										INNER JOIN person p ON p.person_id=brh.person_id_fk
										INNER JOIN bv_week bvw ON bvw.bv_week_id=bvax.bv_week_id_fk
										INNER JOIN cmb_center cc ON cc.cmb_center_id=brh.cmb_center_id_fk
										LEFT OUTER JOIN teacher_group tg ON tg.teacher_group_id=brh.teacher_group_id_fk
										WHERE
										brh.enabled = 1
										AND tg.enabled = 1
										AND brh.year = ' . $this->db->escape($curyear-1) . '
										AND bvax.year = ' . $this->db->escape($curyear) . '
										AND bvw.year = ' . $this->db->escape($curyear) . '
										AND bvw.seq = ' . $this->db->escape($wkSeq) . '
										AND cc.center_name = ' . $this->db->escape($searchcriteria['centername']) . '
										AND brh.session = ' . $this->db->escape($searchcriteria['session']) . '
										AND brh.grade = ' . $this->db->escape($prevgrade) . '
										AND brh.person_id_fk NOT IN
										(
											SELECT
											bvax1.person_id_fk
											FROM bv_attend_xref bvax1
											INNER JOIN bv_reg_history brh1 ON brh1.person_id_fk=bvax1.person_id_fk
											INNER JOIN bv_week bvw1 ON bvw1.bv_week_id=bvax1.bv_week_id_fk
											INNER JOIN cmb_center cc1 ON cc1.cmb_center_id=brh1.cmb_center_id_fk
											LEFT OUTER JOIN teacher_group tg1 ON tg1.teacher_group_id=brh1.teacher_group_id_fk
											WHERE
											brh1.enabled = 1
											AND tg1.enabled = 1
											AND brh1.year = ' . $this->db->escape($curyear) . '
											AND bvax1.year = ' . $this->db->escape($curyear) . '
											AND bvw1.seq = ' . $this->db->escape($wkSeq) . '
											AND bvw1.year = ' . $this->db->escape($curyear) . '
											AND cc1.center_name = ' . $this->db->escape($searchcriteria['centername']) . '
											AND brh1.session = ' . $this->db->escape($searchcriteria['session']) . '
											AND brh1.grade = ' . $this->db->escape($grade) . '
										)
										ORDER BY p.last_name ASC;
									');
									 
					$numres = $tmp->num_rows();
					if( $numres > 0)
					{
						foreach ($tmp->result() as $wkRec)
						{				
							$bvattendancerec = array();
						
							array_push($bvattendancerec, $wkRec->seq);
							array_push($bvattendancerec, $wkRec->bowdate);
							array_push($bvattendancerec, $wkRec->first_name);
							array_push($bvattendancerec, $wkRec->last_name);
							array_push($bvattendancerec, $wkRec->status);
                            $cmb_center_id = $this->Walk_proxy->getCenterID($searchcriteria['centername']);
                            $teacher_group_id = $this->Walk_proxy->getTeacherGroupID($cmb_center_id, $curyear, $searchcriteria['session'], $grade);
							array_push($bvattendancerec, $teacher_group_id);
							array_push($bvattendancerec, "unreg"); //Indicates Unregistered
									
							array_push($bvattendanceweek, $bvattendancerec);
							
							array_push($arridx,strtolower($wkRec->last_name));
							
							unset($bvattendancerec);
						}
					}
*/
				}
				else
                {
			         $prevgrade = $grade;
                }
		
			//Get all new entries for current year (not in previous year)
				$tmp = $this->db->query('
									SELECT
									bvw.seq,
									DATE_FORMAT(bvw.bow_date,' . $this->db->escape("%d-%b-%Y") . ') AS bowdate,
									p.first_name,
									p.last_name,
									bvax.status,
									IFNULL(tg.teacher_group_id,0) AS teacher_group_id
									FROM bv_attend_xref bvax
									INNER JOIN bv_reg_history brh ON brh.person_id_fk=bvax.person_id_fk
									INNER JOIN person p ON p.person_id=brh.person_id_fk
									INNER JOIN bv_week bvw ON bvw.bv_week_id=bvax.bv_week_id_fk
									INNER JOIN cmb_center cc ON cc.cmb_center_id=brh.cmb_center_id_fk
									LEFT OUTER JOIN teacher_group tg ON tg.teacher_group_id=brh.teacher_group_id_fk
									WHERE
									brh.enabled = 1
									AND brh.year = ' . $this->db->escape($curyear) . '
									AND bvax.year = ' . $this->db->escape($curyear) . '
									AND bvw.seq = ' . $this->db->escape($wkSeq) . '
									AND bvw.year = ' . $this->db->escape($curyear) . '
									AND cc.center_name = ' . $this->db->escape($searchcriteria['centername']) . '
									AND brh.session = ' . $this->db->escape($searchcriteria['session']) . '
									AND brh.grade = ' . $this->db->escape($grade) . '
									ORDER BY p.last_name ASC
								');
								 
				$numres = $tmp->num_rows();
				
				if( $numres > 0)
				{
					foreach ($tmp->result() as $wkRow)
					{				
						$bvattendancerecnew = array();
					
						array_push($bvattendancerecnew, $wkRow->seq);
						array_push($bvattendancerecnew, $wkRow->bowdate);
						array_push($bvattendancerecnew, $wkRow->first_name);
						array_push($bvattendancerecnew, $wkRow->last_name);
						array_push($bvattendancerecnew, $wkRow->status);
                        $cmb_center_id = $this->Walk_proxy->getCenterID($searchcriteria['centername']);
                        $teacher_group_id = $this->Walk_proxy->getTeacherGroupID($cmb_center_id, $curyear, $searchcriteria['session'], $grade);
						array_push($bvattendancerecnew, $teacher_group_id);
						array_push($bvattendancerecnew, "reg"); //Indicates registered
	
						array_push($bvattendanceweek, $bvattendancerecnew);
						
						unset($bvattendancerecnew);
						
						array_push($arridx,strtolower($wkRow->last_name));
					}				
				}
				
				if (count($bvattendanceweek) > 0)
				{
					//Sort by last_name
					asort($arridx);
					
					$bvattendanceweeksrt = array();
					foreach ($arridx as $key => $val)
					{
						$idx = intval($key);
						$tmprec = $bvattendanceweek[$idx];
						array_push($bvattendanceweeksrt, $tmprec);
						//echo $tmprec[0].",".$tmprec[1].",".$tmprec[2].",".$tmprec[3].",".$tmprec[4]."</br>";
					}		
									
					array_push($bvattendanceclass, $bvattendanceweeksrt);
				}
				
				unset($bvattendanceweek);
				unset($bvattendanceweeksrt);
			}
			
			return $bvattendanceclass;			
		}
/*
		//Get Balavihar attendance for specified class across all weeks
		public function getBalaviharClassAttendanceData( $curyear, $searchcriteria )
		{
			$tmp = $this->db->query('
								SELECT bw.seq
								FROM bv_week bw
								WHERE
									bw.year = ' . $this->db->escape($curyear) . '
								ORDER BY bw.seq ASC
							');
							 
			$numweeks = $tmp->num_rows();			
			$weekseqarr = array();
				
			if( $numweeks > 0)
			{
				foreach ($tmp->result() as $wkRow)
				{				
					array_push($weekseqarr, $wkRow->seq);
				}
			}
			else
				return $weekseqarr;

			$bvattendanceclass = array();
						
			foreach ($weekseqarr as $wkSeq)
			{
				$tmp = $this->db->query('
									SELECT
									bvw.seq,
									DATE_FORMAT(bvw.bow_date,' . $this->db->escape("%d-%b-%Y") . ') AS bowdate,
									p.first_name,
									p.last_name,
									bvwx.status,
									IFNULL(tg.teacher_group_id,0) AS teacher_group_id
									FROM bv_week_xref bvwx
									INNER JOIN bv_reg_history brh ON brh.bv_reg_history_id=bvwx.bv_reg_history_id_fk
									INNER JOIN person p ON p.person_id=brh.person_id_fk
									INNER JOIN bv_week bvw ON bvw.bv_week_id=bvwx.bv_week_id_fk
									INNER JOIN cmb_center cc ON cc.cmb_center_id=brh.cmb_center_id_fk
									LEFT OUTER JOIN teacher_group tg ON tg.teacher_group_id=brh.teacher_group_id_fk
									WHERE
									brh.year = ' . $this->db->escape($curyear) . '
									AND bvw.year = ' . $this->db->escape($curyear) . '
									AND bvw.seq = ' . $this->db->escape($wkSeq) . '
									AND cc.center_name = ' . $this->db->escape($searchcriteria['centername']) . '
									AND brh.session = ' . $this->db->escape($searchcriteria['session']) . '
									AND brh.grade = ' . $this->db->escape($searchcriteria['gradename']) . '
									ORDER BY p.last_name ASC;
								');
								 
				$numres = $tmp->num_rows();
				$bvattendanceweek = array();
				if( $numres > 0)
				{
					foreach ($tmp->result() as $wkRec)
					{				
						$bvattendancerec = array();
					
						array_push($bvattendancerec, $wkRec->seq);
						array_push($bvattendancerec, $wkRec->bowdate);
						array_push($bvattendancerec, $wkRec->first_name);
						array_push($bvattendancerec, $wkRec->last_name);
						array_push($bvattendancerec, $wkRec->status);
						array_push($bvattendancerec, $wkRec->teacher_group_id);
	
						array_push($bvattendanceweek, $bvattendancerec);
					}
				}
				
				array_push($bvattendanceclass, $bvattendanceweek);
			}
			
			return $bvattendanceclass;			
		}
*/
		//Get Mahasamadhi registrants data for a specified year
		public function getMahasamadhiRegistrantsData( $specifiedyear, $searchcriteria )
		{
			$this->load->model('proxies/mahasamadhi/Mahasamadhi_registration_proxy');
			$this->load->model('values/mahasamadhi/Mahasamadhi_registration_value');

			$mrhinfoarr = array();
						
			$searchstr = " ";
			if (!empty($searchcriteria['registrantlastname']))
				$searchstr = " AND mrh.last_name LIKE '".$searchcriteria['registrantlastname']."%' ";
			
			if (!empty($searchcriteria['registrantfirstname']))
				$searchstr = $searchstr."AND mrh.first_name LIKE '".$searchcriteria['registrantfirstname']."%' ";

			if (!empty($searchcriteria['registrantcity']))
				$searchstr = $searchstr."AND mrh.city LIKE '".$searchcriteria['registrantcity']."%' ";

			if ((!empty($searchcriteria['registrantcountry'])) and ($searchcriteria['registrantcountry'] != "All"))
				$searchstr = $searchstr."AND mrh.country LIKE '".$searchcriteria['registrantcountry']."%' ";

			if ((!empty($searchcriteria['registrantstate'])) and ($searchcriteria['registrantstate'] != "All"))
				$searchstr = $searchstr."AND mrh.state = '".$searchcriteria['registrantstate']."' ";

			$tmp = $this->db->query('			
					SELECT
						mrh.ms_reg_history_id
					FROM ms_reg_history mrh
					WHERE
						mrh.enabled = 1
						AND mrh.year = ' . $this->db->escape($specifiedyear) . $searchstr .
					'ORDER BY mrh.date_created DESC;
					');

			if($tmp->num_rows() > 0)
			{											  
				foreach ($tmp->result() as $mrhRow)
				{
					$ms_registration_value = Mahasamadhi_registration_value::cast($this->Mahasamadhi_registration_proxy->getMahasamadhiRegistrationObject( $mrhRow->ms_reg_history_id ));

					array_push($mrhinfoarr, $ms_registration_value);
				}
			}
	
			return 	$mrhinfoarr;		
		}		

        //Get Mahasamadhi detail registrants data for a specified year
        public function getMahasamadhiDetailRegistrantsData( $specifiedyear, $searchcriteria )
        {
            $this->load->model('proxies/mahasamadhi/Mahasamadhi_registration_proxy');
            $this->load->model('values/mahasamadhi/Mahasamadhi_registration_value');

            $mrhinfoarr = array();
                        
            $searchstr = " ";
            if (!empty($searchcriteria['registrantlastname']))
                $searchstr = " AND mrh.last_name LIKE '".$searchcriteria['registrantlastname']."%' ";
            
            if (!empty($searchcriteria['registrantfirstname']))
                $searchstr = $searchstr."AND mrh.first_name LIKE '".$searchcriteria['registrantfirstname']."%' ";

            if (!empty($searchcriteria['registrantcity']))
                $searchstr = $searchstr."AND mrh.city LIKE '".$searchcriteria['registrantcity']."%' ";

            if ((!empty($searchcriteria['registrantcountry'])) and ($searchcriteria['registrantcountry'] != "All"))
                $searchstr = $searchstr."AND mrh.country LIKE '".$searchcriteria['registrantcountry']."%' ";

            if ((!empty($searchcriteria['registrantstate'])) and ($searchcriteria['registrantstate'] != "All"))
                $searchstr = $searchstr."AND mrh.state = '".$searchcriteria['registrantstate']."' ";

            $tmp = $this->db->query('           
                    SELECT
                        mrh.ms_reg_history_id
                    FROM ms_reg_history mrh
                    WHERE
                        mrh.enabled = 1
                        AND mrh.year = ' . $this->db->escape($specifiedyear) . $searchstr .
                    'ORDER BY mrh.date_created DESC;
                    ');

            if($tmp->num_rows() > 0)
            {                                             
                foreach ($tmp->result() as $mrhRow)
                {
                    //Get detailed registration value object
                    $ms_registration_value = Mahasamadhi_registration_value::cast($this->Mahasamadhi_proxy->getRegistrantDetailInfo($mrhRow->ms_reg_history_id));

                    array_push($mrhinfoarr, $ms_registration_value);
                }
            }
    
            return  $mrhinfoarr;        
        }       

       //Get Mahasamadhi registrants data for a specified year for cearting badges
        public function getMahasamadhiRegistrantsBadgeData( $specifiedyear )
        {
            $this->load->model('proxies/mahasamadhi/Mahasamadhi_registration_proxy');
            $this->load->model('values/mahasamadhi/Mahasamadhi_registration_value');

            $mrhinfoarr = array();
                        
            $tmp = $this->db->query('           
                    SELECT
                        mrh.ms_reg_history_id
                    FROM ms_reg_history mrh
                    WHERE
                        mrh.enabled = 1
                        AND mrh.year = ' . $this->db->escape($specifiedyear) . '
                    ORDER BY mrh.date_created DESC;
                    ');

            if($tmp->num_rows() > 0)
            {                                             
                foreach ($tmp->result() as $mrhRow)
                {
                    //Get detailed registration value object
                    $ms_registration_value = Mahasamadhi_registration_value::cast($this->Mahasamadhi_proxy->getRegistrantDetailInfo($mrhRow->ms_reg_history_id));

                    array_push($mrhinfoarr, $ms_registration_value);
                }
            }
    
            return  $mrhinfoarr;        
        }       

		//Get sum() for registrations for a specified year
		public function getMahasamadhiRegistrantsTotals( $specifiedyear, $searchcriteria )
		{
			$this->load->model('proxies/mahasamadhi/Mahasamadhi_registration_proxy');
			$this->load->model('values/mahasamadhi/Mahasamadhi_registration_value');

			$totarr = array();
						
			$searchstr = " ";
			if (!empty($searchcriteria['registrantlastname']))
				$searchstr = " AND mrh.last_name LIKE '".$searchcriteria['registrantlastname']."%' ";
			
			if (!empty($searchcriteria['registrantfirstname']))
				$searchstr = $searchstr."AND mrh.first_name LIKE '".$searchcriteria['registrantfirstname']."%' ";

			if (!empty($searchcriteria['registrantcity']))
				$searchstr = $searchstr."AND mrh.city LIKE '".$searchcriteria['registrantcity']."%' ";

			if ((!empty($searchcriteria['registrantcountry'])) and ($searchcriteria['registrantcountry'] != "All"))
				$searchstr = $searchstr."AND mrh.country LIKE '".$searchcriteria['registrantcountry']."%' ";

			if ((!empty($searchcriteria['registrantstate'])) and ($searchcriteria['registrantstate'] != "All"))
				$searchstr = $searchstr."AND mrh.state = '".$searchcriteria['registrantstate']."' ";

			$tmp = $this->db->query('			
					SELECT
						SUM(numadultreg) AS adulttotal,
						SUM(numchildreg) AS childtotal,
						SUM(numchykreg) AS chyktotal,
						SUM(amount_committed) AS totcommitted,
						SUM(amount_paid) AS totpaid
					FROM ms_reg_history mrh
					WHERE
						mrh.enabled = 1
						AND mrh.year = ' . $this->db->escape($specifiedyear) . $searchstr .
					'ORDER BY mrh.date_created DESC;
					');

			if($tmp->num_rows() == 1)
			{											  
				$totarr['adulttotal'] = $tmp->row()->adulttotal;
				$totarr['childtotal'] = $tmp->row()->childtotal;
				$totarr['chyktotal'] = $tmp->row()->chyktotal;
				$totarr['totcommitted'] = $tmp->row()->totcommitted;
				$totarr['totpaid'] = $tmp->row()->totpaid;
			}
	
			return 	$totarr;		
		}		
	}		
?>